Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

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.

like image 346
Hemant Parihar Avatar asked Sep 09 '15 18:09

Hemant Parihar


People also ask

Is there a global Gitignore file?

You can also create a global . gitignore file to define a list of rules for ignoring files in every Git repository on your computer. For example, you might create the file at ~/. gitignore_global and add some rules to it.

Is there a default Gitignore?

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.

Where is my global Gitignore file?

By default, the global gitignore path is ~/. config/git/ignore on Unix/macOS and %USERPROFILE%\git\ignore on Windows. The syntax is just like that for . gitignore files.

Where is global Gitignore file windows?

Also, the default and automatic global gitignore file is $HOME/. config/git/ignore .


1 Answers

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.

like image 165
poke Avatar answered Sep 20 '22 23:09

poke