Reputation: 51
Here is my problem (via example steps):
Why does foo.txt appear in branchA and not get "hidden" like hello.txt does?
From my perspective this is a great annoyance and seems like a bug/feature request, but has Git been designed to act this way? I was surprised to find no other people complaining about this.
Upvotes: 5
Views: 1607
Reputation: 471
foo.txt is not appearing in branchA, it's just no longer being ignored because your changes to .gitignore (I assume you committed these to branchB) are lost when you checked out branchA. foo.txt is just an untracked file. Having foo.txt "disappear" when you switch to branchA is saying you want the file deleted from your working directory. This very different than ignoring a file.
You can specify ignore patterns that affect the whole repository regardless of what branch you have checked out using the $GIT_DIR/info/exclude file. This is local to your repository though, so ignore patterns specified in this file will not be propagated to other repositories. See gitignore(5).
Upvotes: 1
Reputation: 11055
It is not a bug. To understand how it works, you need to know a few things.
.gitignore
is not "automatically" applied globally. You need to commit it.commit
the file, or you could stash
it.Also, this question has been asked before, though I don't blame you for not finding it in the search. Working on two unrelated files in separate git branches
Upvotes: 4
Reputation: 1044
The quick answer:
Upvotes: 0