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?
10 Answers
- Remove
.pyc
files usinggit rm *.pyc
. If this not work usegit rm -f *.pyc
- Commit
git commit -a -m 'all pyc files removed'
- Push
git push
- In future commits you can ignore
.pyc
files by creating a.gitignore
file
-
2In addition to the fourth point: You **can** use [gitignore.io](https://www.gitignore.io/api/python), but double check the entries. – Darius May 25 '15 at 21:58
-
_Additional info about .gitignore file_ content ,add this line `*.pyc` in your .gitignore to ignore every .pycin future after removing as stated above – Tara Prasad Gurung Mar 30 '17 at 07:16
-
and indeed adding it to .gitignore will help in future. – user3341078 Sep 03 '19 at 16:22
-
1if your using zsh and it says it can't find any files ending in .pyc add `unsetopt nomatch` in your zshrc. – Taylor Nov 09 '19 at 20:03
-
In zsh we should use double quotation: `git rm "*.pyc"` – Ali dashti Apr 29 '23 at 07:00
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:
*.pyc
*~
*.swp
*~ and ~.swp are other commonly forgotten file types that are often accidentally pushed. See the github doc on gitignore https://help.github.com/articles/ignoring-files (and their repo of .gitignore files for some nice defaults).

- 5,875
- 24
- 37
This works for me,
find . -name '*.pyc' | xargs -n 1 git rm --cached

- 269
- 3
- 9
-
1This works better than the accepted solution for .pyc files which are in subdirectories – agakshat May 04 '18 at 15:16
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

- 111
- 1
- 5
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)

- 7,016
- 5
- 54
- 92
Because in default Bitbucket, there is no .gitignore file in the repo,so you can do :
- you can create local .gitignore(should not be pushed) and add *.pyc as a line;
- 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!

- 339
- 1
- 2
- 10
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 :)

- 11
- 3
A one-liner for fun:
git status | grep pyc | sed -e 's/ new file: //g' | xargs -I {} git rm --cached {}

- 2,858
- 1
- 30
- 38
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.

- 11
- 2