31

I have a file config-dev.php which will be used as a dev version config.

Now, another developer wants to make his own changes in this file.

When he commits, this file is commited and my config-dev.php is overwritten by the file from my coworker.

this file is in .gitignore but it is still not working.

How do I remove this file from git index so everyone can have its own config-dev.php?

I tried git rm --cached config-dev.php but it is still not working. Should this command be executed by all the coworkers? or should I sync after git rm??

MilMike
  • 12,571
  • 15
  • 65
  • 82
  • 1
    That's odd. Did you `commit` and `push` after doing the `git rm`? Also, this is a duplicate of [this post](http://stackoverflow.com/questions/1274057/making-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitignore) though there it's not stated explicitly that you need to `commit` and `push` the change. – houtanb Nov 06 '15 at 11:01
  • Also relevant: [Stop tracking and ignore changes to a file in Git](http://stackoverflow.com/q/936249/216074) and [What's the easiest way to deal with project configuration files?](http://stackoverflow.com/q/6782017/216074) – poke Nov 06 '15 at 11:05

1 Answers1

52
  1. remove the file from tracking:

    git rm --cached config-dev.php && git commit -m "config-dev.php"
    
  2. add it to the .gitignore

    echo config-dev.php >> .gitignore
    git add .gitignore
    git commit -m "adding config-dev.php to .gitignore"
    
  3. Publish these changes

    git push
    
  4. On your colleagues machine fetch the new configuration

    git pull
    

Done

When your other dev gets errors on pull because of changes in her config-dev.php, she should copy her local changes away and then rename the file back after pushing:

cp config-dev.php my-config-dev.php
git checkout config-dev.php
git pull
mv my-config-dev.php config-dev.php
eckes
  • 64,417
  • 29
  • 168
  • 201