Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't .gitignore work across branches?

Working on a local Git (cloned) repository, I have created a branch and placed .gitignore file within it to exclude few directories from git commit. It works just fine, but after switching to a different branch, those directories (the excluded ones) appear in it (on the branch which does not include those directories).

Is it a normal Git behavior? If so, what is the best practice to avoid the issue above?

like image 787
Mr. Avatar asked Feb 19 '23 11:02

Mr.


1 Answers

The .gitignore file is a file in the repository just like any other. So if you create a new .gitignore file, commit it on one branch, then switch to another, the .gitignore file will disappear. This is normal.

like image 154
Greg Hewgill Avatar answered Feb 27 '23 07:02

Greg Hewgill