I want to ignore certain files within a branch without having to rely on a tracked .gitignore
file that will be overwritten during merges with other branches.
I’ve closely followed a Stack Overflow answer along with the linked blog post, but my repo doesn’t seem to be recognizing the specified excludesfile
in my .git/config
. The Git documentation (git-config
, gitignore
) doesn’t seem to show how to specify and address an excludes file for a specific branch.
My .git/config
looks like this:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
excludesfile = +/info/exclude
[branch "myspecialbranch"]
excludesfile = +/info/exclude_specialbranch
My .git/info/exclude
file looks like this (by default, I didn’t touch it):
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
.DS_Store
I don’t have a .gitignore
file in my “specialbranch”.
If I try to ignore a file like info.php
, my .git/info/exclude_specialbranch
file looks like this:
info.php
… but it doesn’t ignore the file.
If I run git status --ignored
, it only lists the .DS_Store
file from the default exclude
file.
However, if I add info.php
to my .git/info/exclude
file:
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
.DS_Store
info.php
it ignores the file perfectly.
Note that it still works without the line excludesfile = +/info/exclude
under [core]
in .git/config
. Git seems to know where the system-wide exclude
is without me having to tell it.
I have a feeling that .git/config
isn’t recognizing the address of my custom excludes file:
excludesfile = +/info/exclude_specialbranch
… most likely because of the use of +
to describe the location of the .git
directory.
What’s the correct method for addressing custom exclude files in the (more recent) versions of Git?
I’m running OSX 10.9.5 and Git version 2.2.1.
See Question&Answers more detail:
os