Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: untrack a file in local repo only and keep it in the remote repo

Tags:

git

I have a NetBeans file "nbproject/project.properties" that always shows up in the "Changes not staged for commit" section (when I do git status). How could I move this to the Untracked files section (without adding it to .gitignore) ? I tried this command git rm --cached but what happened is the file shows as untracked in my local repo and got removed in the remote one but what I want is to keep it in remote and untrack only in local repo.

like image 425
Jimmy Avatar asked Jul 22 '11 14:07

Jimmy


People also ask

How do I permanently Untrack a file in git?

You can of course use git rm --cached , which removes it only from the index, leaving it untouched in the work-tree.

How do I make a file untracked?

Tell Git to untrack file Use git rm to Git untrack file. Both of the commands above git untrack file without deleting. This is because of the cached option. Removing the cached option will delete it from your disk.

How do I add untracked files to my repository?

The easiest way to add all files to your Git repository is to use the “git add” command followed by the “-A” option for “all”. In this case, the new (or untracked), deleted and modified files will be added to your Git staging area.

How do I make a track untracked in git?

“git untrack file” Code Answer's git rm -r --cached . – Remove all tracked files, including wanted and unwanted. Your code will be safe as long as you have saved locally. git add .


1 Answers

You could update your index:

cd /root/folder/of/your/repo git update-index --assume-unchanged nbproject/project.properties 

and make sure it never shows as "updated" in your current repo.
That means it won't ever be pushed, but it is still present in the index.
(and it can be modified at will in your local working tree).


  • to revert that state (from git-ready):

git update-index --no-assume-unchanged <file>

  • to see all assume unchanged files (from Gabe Kopley's comment)

git ls-files -v | grep '^h '

like image 150
VonC Avatar answered Sep 20 '22 13:09

VonC