Git Ignore not working


Here is my scenario. I was on branch A, where I made some changes to certain file on my local working copy.


I basically want the following:

  1. Ignore the changes made to this file completely. I accomplished this using
  2. Untrack this file from version control, which I tried to accomplish using .gitignore.

  3. Preserve the changes to this file on my local working folder as I checkout different branches.
    A->Develop->B->C etc…

It is #3 that I am not able to accomplish. As soon as I checkout a new branch and do a pull, the old changes are overwritten on the file.

Why is this happening? Shouldnt inclusion of this file path into .gitignore effectively take out this file completely out of reach of the version control tentacles?

How can I achieve #3?

This question is unlike the one mentioned in the “possible duplicate” link.
Heres why:

Here’s basically what I want in lay words. “Put this one particular file of mine in essentially a ‘shell’, that neither gets overwritten during ANY git operations nor gets taken into account if changed”. Its basically excluding any form of version control synchronization between that file and staging/remote. This local file and the version on staging/remote must exist with mutual and total disconnection.


This is happening because the file is already part of the repository. So when you switch branches you get the version of this file from the branch you are checking out. The gitignore file only prevents git from seeing files that are not a part of the repository. This is done, so git doesn’t include certain files in commands like git add . or git commit -a. And assume-unchanged option tricks git into not seeing the changes, but that means that Git feels free to overwrite the file on checkouts, since it knows the file to be no different from the committed version.

If what you want is to remove this file from git control and manage the changes to it yourself, you can use git rm --cached /launcher/file.esb and commit the change. This will remove this file from the index and the file will no longer be tracked by git. The --cached option prevents git from actually removing the file from your working directory. You might have to do this separately for each branch though, since removing file from one branch doesn’t remove it from other branches. To do this you might want to undo assume-unchanged and then use git stash command to temporarily stash your local changes.

Answered By – Mad Wombat

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published