GIT: How to keep ignored files when switching branches?

I have an App.Local.config file which each developer has their own settings in. I do not want this file checked versioned in the GIT repo as every time it would be overwritten by another developers changes.

So I deleted the file from the repo and added it to the ignore file. But now when developers switch branches, App.Local.config is deleted from their local filesystem.

  • Git post-checkout - how to reject push if Composer installation fails
  • Getting Clear read only status on Webstorm 8
  • Remove GitHub commit history for particular day
  • What are all these hidden ('._' prefixed) files that are in my git repo?
  • Picking commit objects in Git
  • git merge conflict due to renaming in two branches - how to fix & avoid in future?
  • Ultimately what i would like is:

    1. new dev clones repo, gets a starting version of App.Local.config
    2. dev makes changes to App.Local.config. Git will ignore changes and not stage/checkin
    3. dev switches branches, changes to App.Local.config will not be lost and file is not deleted.

    How can I do that?


  • How do I manage conflicts with git submodules?
  • Forcing a timeout in git push + pull
  • Multiple Android projects with same GIT submodule
  • Merging two github accounts
  • Why does git fetch fail with “Could not resolve host: (nil)…” with origin?
  • Best workflow for software development with many release versions
  • 2 Solutions collect form web for “GIT: How to keep ignored files when switching branches?”

    What probably happened is that you removed the file from your workspace but not from the index. If you did that git thinks that removing this file is a change and it will remove it from then on.

    The way to go is to remove the file you don’t want to track anymore from the index with

    git rm --cached App.Local.config

    and then add that file to the .gitignore
    Doing that you will have no more problems with the file

    Seems like this file was in index once. So its deletion is a change. You can add it to .gitignore or .git/info/exclude and then just recreate it on each developers machine.

    Git Baby is a git and github fan, let's start git clone.