All Systems GOAT

Untrack a git file already added

oops, should have added that to .gitignore

Step 1: Make sure everything is committed, including gitignore.

Before you run this command, be sure that the correct exclusions are listed in your .gitignore file. THEN commit. Otherwise nothing will change.

git commit -m "oops, that file should not be there."

Step 2: Remove all the cached files

Don’t worry, all your files will be there, this only removes them from git’s list.
git rm -r --cached .
  • rm tells git to remove files
  • -r is a standard command line flag that means to perform the command recursively (inception for files)
  • —cached is the thing that specifies the index should forget files, but not delete them from your computer
  • . (dot) means all files will be untracked (git forgets them)

Step 3: Re-Add all your files, which will now exclude the ones in gitignore

…that I hope you fixed in Step 1
git add -A

or

git add .

Step 4. Commit everything

git commit -m "gitignore fix #451"
  • -m is for message, which is required. You can add whatever message is meaningful to you, even if it is “blah, oops, yucky…”

Step 5: Now, push everything to your repo to record the changes

Replace “master” with your own branch name if different
git push origin master

Ryan Carter

Written by Ryan Carter who lives and works in Colorado. WARNING: all posts are thoughts in progress and subject to change at any time without notice. Enjoy.
check out my... Stack OverflowQuora AnswersCSS Library: Diet BulmaOld IE Inspector: Antiquated