Skip to content

Instantly share code, notes, and snippets.

@bendog
Created January 19, 2023 05:53
Show Gist options
  • Save bendog/25f13cf83ef0db283dc656cc58a5c7d7 to your computer and use it in GitHub Desktop.
Save bendog/25f13cf83ef0db283dc656cc58a5c7d7 to your computer and use it in GitHub Desktop.
Remove *.pyc files from your python project repo

Remove .pyc files from your Python project git repo.

Here are a collection of command line arguments, which will help you fix your issues with .pyc files.

1. Prepare for your change

Go to your project root, the folder which is the base of your git repo.

Make sure your project is up to date with your remote, run git fetch

Make sure you are on your main branch, run git checkout main

Make sure your local branch is up to date, run git pull

2. Update your .gitignore

Update your git ignore, add these lines to the .gitignore file in your project root.
(Don't include the ... those are to signify there may be existing content which you do not remove.)

...
# Python temp files
__pycache__/
*.py[cod]
*$py.class
...

3. Remove the pyc files which have already been stored.

Remove .pyc files using git rm -f *.pyc

Commit the changes git commit -am 'update to remove all pyc files'

Push your update git push

4. Update your other branches

Update your other branches by following this process.

select your branch, run git checkout <branch name> where branch name is the name of your branch
(do not include the < and > )

check your branch is up to date, run git pull

merge in your changes from main, run git merge main

remove your pyc files, run git rm -f *.pyc

commit the changes with git commit --no-edit

check your repo is happy with git status

if happy, push your changes git push

repeat this for each branch you need to fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment