mrfr
mrfr

Reputation: 1794

Untrack file but not remove it

How can I untrack a file but not remove it from upstream?

When I tried to do: git rm --cached "file" then it says that its deleted.

then I add and commit and push it. Now the file has been removed from upstream.

This is not what I want. I want it to still be in the upstream, but not longer tracked for changes on my local. Can this be done?

Upvotes: 0

Views: 116

Answers (1)

eedrah
eedrah

Reputation: 2385

You want:

git update-index --skip-worktree <path-name>

This will ignore all local changes, but will still track the file in other remotes. This also has the added benefit of showing if changes happen to that file on a remote, and managing it correctly - showing conflicts with your local, etc.

Do not use --assume-unchanged - this does not have those safeguards in place, and will do things like overwrite your local changes without warning if a remote changes the file, and start retracking it again.

See this and the linked blog post for more information on the difference.

Upvotes: 1

Related Questions