git, don't show me *.pyc in the list of untracked files!
Solution 1
git config --global core.excludesfile "c:\program files\whatever\global_ignore.txt"
Then, add
*.foo
to that file.
Solution 2
As mentioned in gitignore, git has 3 ignore files:
- Patterns which should be version-controlled and distributed to other repositories via clone (i.e., files that all developers will want to ignore) should go into a
.gitignore file
.
(that takes care of all time: if one clones your repo, it will get the .gitignore file)
- Patterns which are specific to a particular repository but which do not need to be shared with other related repositories (e.g., auxiliary files that live inside the repository but are specific to one user's workflow) should go into the $GIT_DIR/info/exclude file.
(not interesting in your case)
- Patterns which a user wants git to ignore in all situations (e.g., backup or temporary files generated by the user's editor of choice) generally go into a file specified by
core.excludesfile
in theuser's ~/.gitconfig
.
(takes cares of all projects, but not all time since it is not replicated when one clones your repo.)
"All time for all projects" would means for instance a custom shell for creating new git projects, with a custom .gitignore as first file part of the first commit...
Solution 3
Put in the file ~/.gitignore
:
*.pyc
Run:
git config --global core.excludesfile ~/.gitignore
I agree with @David Wolever this option should be used with caution if ever.
The ~/.gitignore
("%HOME%\.gitignore"
on Windows) is just a convention you can use any filename you like e.g., "c:\docs\gitignore.txt"
.
Solution 4
Another way to ignore some file patterns is: add *.pyc to .git/info/excludes, this is a much cleaner way.
Solution 5
add
*.pyc
in .gitignore file
and run this
git config --global core.excludesfile .gitignore
which worked for me
Comments
-
hasen about 4 years
When doing:
>git status
It shows a big list of .pyc files under "untracked files". I don't want it to show these, as it adds noise.
In other words, how do I make git ignore .pyc files all the time and for all projects?
EDIT
I'm not asking for a way to spread my ignored files to other people, I really just mean "for all projects", meaning I don't want to configure each new project to ignore .pyc files.
UPDATE
I should add that I'm working on windows, and my git is msysgit
Patterns which a user wants git to ignore in all situations (e.g., backup or temporary files generated by the user's editor of choice) generally go into a file specified by core.excludesfile in the user's ~/.gitconfig.
Is .gitconfig a file or a folder? I don't have such a thing in my home directory (
C:\users\<myusername>\
)UPDATE2
Thanks everybody for the responses,
I solved the issues by using:
>git config --global core.excludesfile c:\git\ignore_files.txt
and putting *.pyc in
c:\git\ignore_files.txt
-
jfs about 15 years
.gitignore
for a git repository doesn't work for "all the time and for all projects". -
jfs about 15 years
bzr
is written in Python. It would be unexpected if it couldn't handle Python specific stuff well. -
David Wolever about 15 yearsThat's true. I don't know the full extent of the defaults, but I know they also handle things like Vim/Emacs swap/backup files, .o files, etc.
-
ILIA BROUDNO about 15 yearsone would think it would be sensible for bzr to ignore .DS_Store files one mac, but it doesn't, svn does ad I recall. I think it only ignores pyc files by default is it's written in python and probably in emacs too :)
-
mipadi about 15 yearsWhy would the implementation language of bzr dictate what files it ignores? By that logic, Git should ignore *.o files by default.
-
Bombe about 15 yearsOops. Use “git config --global core.excludesfile …” to set it in Git’s global configuration. That should work for all projects.
-
jfs about 15 years+1: Comprehensive answer. Except you should mention that
core.excludesfile
could be set per project as well as global setting. -
LazerSharks almost 9 yearsWhy should this be used with caution?
-
jfs almost 9 years@Gnuey: it is a global setting that is applied to all your git repositories. Use it only for files that you want to ignore "all the time and for all projects"
-
jfs almost 9 years@9000: "isn't working for me" is not very informative. What commands did you run? What other solutions have you tried? Does any of them work for you? What did you expect to happen? What happens instead? What is your OS,
git
version? If None of the current answers work for you then ask a separate SO question. -
sudo almost 9 years@J.F.Sebastian I edited
~/.gitignore
, added the line, then ran the command you listed. Also did that in my git repo's.gitignore
to be safe. I then ran git status and still saw a bunch of untracked, unignored PYC files. The thing is, I ignore other file types like this without problems, but these PYC files specifically refuse to be ignored. If it matters, these PYC files are generated by PyCharm. I have git version 2.3.2 (Apple Git-55). Sorry for the initial bad comment; I was really frustrated with PYC files clogging up my git repo and not being able to ignore them. -
sudo almost 9 years^ I meant to say "unstaged", not "untracked". ANYWAY, I did some testing... It turns out that you can't ignore files after they've already been added to git's tracked files and committed at least once. My PYC files had already been committed before, so it's too late. I didn't know that. Worth noting.
-
jfs almost 9 years@9000: gitignore works only with untracked files. It has no effect otherwise. See the NOTES section in the docs.