Remove .pyc files from Git remote repository

Accidentally, I have pushed the .pyc files to the master repository. Now I want to delete them but I can´t do it. Is there any way to remove them directly from the Bitbucket site?

Thanks in advance.

  • git rejected push non-fast-forward
  • Mingw+msys2 : Failed to connect to : Network is unreachable
  • Can Git software (e.g. Gitbox, Github, SourceTree) use a remote repo instead of local?
  • How can we capture a pull request which is created in bitbucket cloud
  • Deploy web project under GIT version control to shared hosting
  • How do I delete/remove a push from Bitbucket?
  • Why is git apply of a patch with binary files not creating the binary files?
  • github http clone returns 'did you run git update-server-info on the server'
  • Is it still possible to restore deleted untracked files in git?
  • When creating a git repository that will be on the server, can I convert it to a bare repository?
  • git branch with multiple upstreams
  • How to make eclipse neon show git branch in package view?
  • 10 Solutions collect form web for “Remove .pyc files from Git remote repository”

    1. Remove .pyc files using git rm *.pyc. If this not work use git rm -f *.pyc
    2. Commit git commit -a -m 'all pyc files removed'
    3. Push git push
    4. In future commits you can ignore .pyc files by creating a .gitignore file

    No, you cannot delete them directly from the BitBucket interface but you can delete them in your local checkout and find ./ -type f -name '*.pyc' -exec git rm {} \; ( or simply git rm each pyc file one by one ). Then commit/push your changes.

    Finally, to avoid ever making the same mistake again you may create a file at the root of your repo and name it ‘.gitignore’ with the contents:


    *~ and ~.swp are other commonly forgotten file types that are often accidentally pushed. See the github doc on gitignore (and their repo of .gitignore files for some nice defaults).

    git rm *.pyc --cached
    git commmit -a -m'remove pyc from index'
    git push

    PS: I see the date of question, but this solution looks better, imho. May be it’ll help someone.. .

    Because in default Bitbucket, there is no .gitignore file in the repo,so you can do :

    1. you can create local .gitignore(should not be pushed) and add *.pyc as a line;
    2. you can copy the .gitignore in Github repo and add *.pyc as a line in this file! You can push it or keep it in your local repo!

    Quick way with PyDev for eclipse.

    Go to the PyDev Package Explorer of your project and do:

    • right click + Pydev / Remove *.pyc *.pyo and *$py.class File

      a window will popup telling you how many files have been deleted.

    Optional: Commit your change to the team/server:

    • right click + team / commit

    In the commit window you shouldn’t see any .pyc available to add as we deleted them.
    Also if you committed such files before then you should be able to commit their “deletion” now.

    ===> Your local and server repository are now free of *.pyc *.pyo and *$py.class File 🙂

    I used simeg’s solution but also wanted to deleted tons of *.pyc files added by mistake to a branch. I used awk to delete them from cache recursively.

    git status | awk '{if($1=="modified:" && $2!=".gitignore") ; system("git rm --cached "$2)}'

    Then, I deleted the files from my local

    find . -name *.pyc -delete

    To remove all .pyc files use git rm -rf *.pyc

    Then add the *.py[co] to your .gitignore file. (This will prevent .pyc and .pyo files from getting committed in the future commits)

    Thie worked for me,

    find . -name '*.pyc' | xargs -n 1 git rm --cached

    A one-liner for fun:

    git status | grep pyc | sed -e 's/ new file: //g' | xargs -I {} git rm --cached {}

    another liner for fun to remove all the pyc files.

    find . -name ‘*.pyc’ -exec git rm {} \;

    don’t forget to follow the steps in other answers to commit and add gitignore.

    Git Baby is a git and github fan, let's start git clone.