+2 votes
1 view
in Devops and Agile by (20k points)
How can I ignore .pyc files in git?

If I put it in .gitignore it doesn't work. I need them to be untracked and not checked for commits.

1 Answer

+1 vote
by (28.4k points)

Add the following line to the .gitignore file in the root folder of your git repository tree right after repository initialization.:


Also, in case you forgot to do it beforehand, and you just add the line to the .gitignore file, all previously committed .pyc files will still be tracked, so you'll need to remove them from the repository.

Say, you are on a Linux system (or "parents&sons" like a MacOSX), you can quickly do it with just this one line command that you need to execute from the root of the repository:

find . -name "*.pyc" -exec git rm -f "{}" \;

It means starting from the directory I am currently in, find all files whose name ends with extension .pyc, and pass file name to the command git rm -f

After *.pyc files deletion from git as tracked files, commit this change to the repository, and then you can finally add the *.pyc line to the .gitignore file.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !