Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

github

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??

like image 809
MilMike Avatar asked Nov 06 '15 10:11

MilMike


People also ask

How do I remove a file from git tracking?

To remove a file from Git, you have to remove it from your tracked files (more accurately, remove it from your staging area) and then commit. The git rm command does that, and also removes the file from your working directory so you don't see it as an untracked file the next time around.

How do I change tracked files in git?

In this git gives a suggestion to the user that the tracked file on staging can be removed by using git rm --cached <file> . To practice the command, let's try removing the same CustomerData_IND. txt file, which was added earlier. To remove the desired file, type git rm --cached CustomerData_IND.


1 Answers

  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
like image 164
eckes Avatar answered Oct 19 '22 12:10

eckes