I have two branches, which contain a file that has recently been added to git ignore. It is an auto-generated file. I removed it in the master branch from the cache using git rm --cached fileName. However, i still get the message that he file would be overwritten when I try to change to the second branch using git checkout branchName. How can I get both branches to ignore the file, it seems like a catch to me - in order to change branch I would have to add the file again and commit it. I don't want to use git stash, since there are other changes I don't want to be persisted.

  • 1
    Did you commit the removing of the file?
    – pfnuesel
    Sep 16, 2016 at 11:00

2 Answers 2


Commit your current changes and remove fileName.


You can cherry pick the commit (assuming that it only contained the file removal) to your branch.

git cherry-pick <commit hash>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .