Keeping some local changes when checking out with --force

27 Views Asked by At

The situation: I have a local git repository which is a clone of a remote repository. Suppose the repository is tracking (among others) two files, fileA and fileB.

After cloning the repository, I modify fileA and fileB locally, but I never stage or commit those changes.

Eventually, I will need to run git checkout --force origin/master on the local repository to fetch the newest version from the remote repository. Now all the changes I made locally (on files tracked in the remote repository) will be overwritten.

The problem: How can I configure the local repository to always keep changes I made to fileA, yet overwrite fileB? I basically want fileA to be ignored locally although it is a tracked file in the remote repository.

Adding fileA to .gitignore or .git/info/exclude did not work, probably because those two files only prevent files from added to tracking, not from being tracked once they are in the index.

git rm --cache fileA did not work either, since fileA is still in the index at origin and thus will be overwritten locally when I check out.

tl;dr: I want to instruct git to not touch certain files in my repository even though they are being tracked in a remote repository.

0

There are 0 best solutions below