0

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.

Lars Ebert
  • 3,487
  • 2
  • 24
  • 46
  • 1
    `I basically want fileA to be ignored locally although it is a tracked file in the remote repository` ... you can't do this in Git AFAIK. Files which are tracked in the repo are not ignored, and vice-versa. Something like update index assume unchanged also would not do what you want, because there could be conflicts when you pull. – Tim Biegeleisen Dec 22 '16 at 11:30
  • 1
    The short answer is "don't do that": instead, layer something atop Git, where you have Git manage the repo over in Location A, and then you manually-or-automatically copy everything-but-certain-files from A to your "real place" B. (But life gets much easier if you just use files that aren't version-controlled for the actual configuration of your deployed software.) – torek Dec 22 '16 at 23:57

0 Answers0