Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git global ignore not working

Tags:

git

I've created the file .gitignore_global and put it in my git install directory. When I run the command:

git config --global core.excludesfile ~/.gitignore 

the rules in the ignore file do not get applied to my commits.

When I rename the file .gitignore and put it in my project root, the rules do apply.

What is wrong here?

like image 910
user880954 Avatar asked Sep 23 '11 12:09

user880954


People also ask

Is there a global git ignore?

You can set up a global . gitignore file that lists files that will be ignored on all Git projects. This is the preferred way of ignoring editor artifacts, toolchain log files, OS files, and other miscellaneous crap.

Why is git ignore not ignoring?

gitignore file isn't ignoring your files and directories. . gitignore just ignores files that have not yet been added to the repository. If you have already git added certain files, their modifications will be tracked.


2 Answers

Maybe you need to do:

git config --global core.excludesfile ~/.gitignore_global  

And to have some coffee.

like image 125
CharlesB Avatar answered Sep 20 '22 11:09

CharlesB


Thought I would chip in on this. There is another reason why the global ignore file appears not to be working. It's something that I don't think has been covered in earlier answers. It's so blindingly obvious that - of course - it's very easy to miss.

It is, that git will only ignore new files. If the file is already being tracked by git, then of course git will not ignore it! So whatever patterns in any gitignore or exclude file do not apply.

That makes sense. Why would git want to ignore modifications to files it is already tracking? If the file is to be ignored, you must first tell git not to track it, then git ignore it as described in the manual. For info on how to untrack files, see this answer.

This all leads me to ask, is it possible to ignore changes to tracked files? Again, git delivers. This answer; Git: Ignore tracked files gives us the command (replace file with the file you want to ignore):

git update-index --assume-unchanged file

Finally, here's some additional info on debugging git ignore.

The gitignore(5) Manual Page tells us:

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. Its default value is $XDG_CONFIG_HOME/git/ignore. If $XDG_CONFIG_HOME is either not set or empty, $HOME/.config/git/ignore is used instead.

So, this is new and replaces the previous ~/.gitignore_global mentioned previously.

Next, and this is really useful, is that as of 1.8.2, we now have some excellent debugging tools. Have a look at:

Git Learns to Ignore Better - New in 1.8.2

This shows how to use the new check-ignore flag to verify that git is successfully ignoring your patterns, e.g.

git check-ignore bin/a.dll --verbose

like image 26
Max MacLeod Avatar answered Sep 22 '22 11:09

Max MacLeod