1

I need to have a file on my repository that other developers can modify on their local copy while having Git ignore those changes.

Can't use git rm --cached <file> because the file is removed from the remote, making the file unavailable for future clones/pulls.

Can't use git update-index --assume-unchanged <file> nor git update-index --skip-worktree <file> because technically the file is still being tracked since git spits out this error message on any work tree overriding operations (e.g. git checkout or git merge) if the developer modifies the file:

"Please commit your changes or stash them before you switch branches. Aborting"

Can't add the file to .gitignore because it has been tracked already.

Is there any Git operation I can use to achieve this?

Thanks.

3
  • I'm curious, why is the file even in the repo? If everyone has their own customized copy of it, it's not really part of the codebase, but more like a config file, right? So why not put a template in the repo instead of the live copy? (To be clear, I'm still learning software development.) Commented Sep 7, 2020 at 0:25
  • @wjandrea Your sort of answer your own question. Correct, is a template config file where the dev can insert an API key for example, but we don't want that API being pushed to the repo. Commented Sep 7, 2020 at 0:29
  • Right, so why are you putting it in the repo instead of, say, the user's home folder? Commented Sep 7, 2020 at 0:31

1 Answer 1

4

There is no way to allow ignoreable changes to the file in the local copy. The Git FAQ explains this thoroughly.

If you want to use a template file, don't name it the same thing as the file you want it to end up as. Name it something different, then either copy it into place with a script or let the user copy it into the right place, and ignore the actual configuration file while tracking the template.

Sign up to request clarification or add additional context in comments.

1 Comment

That's unfortunate. It makes sense why it doesn't work though. Thanks!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.