How to remove a file from being tracked by git? [duplicate]

  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

Leave a Comment