Search code examples
gitgit-mergegitignoregit-checkout

Why .gitignore files are appearing in master while they are ignored in development branch?


I have a development branch, where in one of the sub-directories I created a .gitignore file, added the file(s) to be ignored, committed and pushed the change to development branch. But now when I checkout to master (because I want to merge development to master), the ignored files show up as unstaged changes. Why does it happen this way? What am I doing wrong in the workflow? How can I fix it? (I am using VS code for my work).


Solution

  • The files are untracked, so Git will not touch them when you change branches.

    The development branch has a .gitignore, so they are ignored when development is checked out. When you checkout master the untracked files are still there, but there is no .gitignore file; they show up as untracked.

    Merge development into master. Then master will have the .gitignore file and they will be ignored.