faber faber - 1 year ago 117
Git Question

Git update local ignoring few files (is not .gitignore)


file1 - person1 is working on it
file2 - person2 is working on it
file3 - common with personal hardcoded configuration
untracked files

person1 commits and pushes his changes on file1.
How person2 can update file1 in his local without resetting file2, file3 and untracked files?
It's a while that I'm trying to do it but I still don't find an easy way!

Answer Source

Untracked files won't be updated when you fetch new commits from the remote repository. As for file2 and file3 (which I'm assuming are tracked), you'll want to set the skip-worktree flag on those. That way Git won't update them in your working directory.

From the documentation:

When one of these flags is specified, the object name recorded for the paths are not updated.

More specifically:

When reading an entry, if it is marked as skip-worktree, then Git pretends its working directory version is up to date and read the index version instead.

You can set the skip-worktree flag on a specific file with the git-update-index command:

git update-index --skip-worktree path/to/file2

If you later want to unset the flag, use the --no-skip-worktree option instead:

git update-index --no-skip-worktree path/to/file2
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download