Hemant Parihar
Hemant Parihar

Reputation: 752

.gitignore_global is not working, even .gitconfig shows the .gitignore_global

I created the .gitignore_global file and save it to the directory where i have .gitconfig file.

After then, i used this command.

git config --global core.excludesfile .gitignore_global

then i checked my .gitconfig file by using the command

cat .gitconfig

It shows me result as

[user]
        email = [email protected]
        name = Hemant Parihar
[gui]
        recentrepo = C:/Users/heman/gitprojects
        recentrepo = E:/Inspiration/developerquery
[filter "lfs"]
        clean = git-lfs clean %f
        smudge = git-lfs smudge %f
        required = true
[core]
        excludesfile = .gitignore_global

It clear shows me in [core] section, there is .gitignore file. But in my project repository i created a file which should be ignored as i configure the .gitignore_global. But that should not happen. But when i used local .gitignore file to my project, it works fine and ignore the files which should not be tracked.

My project repository directory is E:/Inspiration/server/explore_california while .gitignore_global is in my home directory (where .gitconfig file is present.).

I checked this link but i did not find anything that is helpful.

Upvotes: 28

Views: 16637

Answers (1)

poke
poke

Reputation: 387775

The path to the global gitignore needs to be absolute, so you could use the shell expansion here and just specify it as ~/.gitignore_global:

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

In order to understand what’s going on if you don’t use an absolute path, you have to understand how git configs work: Every repository has one in .git/config. In addition, there is the global ~/.gitconfig. Configuration values from both places are merged (with the local repository settings taking precedence in case of conflicts) to produce a single set of configuation settings. You can inspect those by running git config -l inside a local repository.

So configuration is always local to the current repository. So when you have a relative path to a “global” excludesfile, that path is interpreted relatively to your repository.

So with excludesfile = .gitignore_global, Git would look into your local repository for a file gitignore_global. And it would use that as well as the normal .gitignore and the repository’s .git/info/exclude.

So you could actually place a .gitignore_global file into every repository and Git would pick it up.

So since you want a global configuration, you need to specify an absolute path.

Upvotes: 57

Related Questions