When changing .gitignore, should all developers run `git rm --cached <path>`?

If I add an already tracked Git file .gitignore

, I can simply run

git rm --cached <path>

      

to apply the new rules. I push this to the server and the server will no longer receive my changes. Should I tell everyone on my development team that they need to run the command git rm

so that no one makes any changes to the new file?

+3


source to share


1 answer


Should I tell everyone on my development team that they need to run the command git rm

so that no one makes any changes to the new file?

Short answer

Not. All you have to do is commit and push to remote.

Detailed answer

If you want to start ignoring a file that is already being tracked with Git, you really need to



  • add an entry for it in .gitignore

    and
  • run git rm --cached <path>

    to stop tracking a file (Git cannot ignore files that are currently being tracked).

Now if you commit and push to the remote, this file will no longer be tracked in the remote repo. So after your contributors use the latest changes from the remote machine in their local repositories (for example by pulling), this file will not be tracked in their own repositories either. Therefore, they will not need to run

git rm --cached <path>

      

In addition, since yours .gitignore

is part of the repository
(i.e., it is tracked by Git), your employees won't even need to add an entry for the file in question; the entry will already be in .gitignore

, as part of your changes that they pushed into their local repositories.

Of course, that assuming no one is pushing the force (which could erase your changes) after you clicked ...

+3


source







All Articles