-1

I've cloned a remote repository which contains a specific file. This file requires that I edit and keep a version of it which must be different from the one in the remote repository. Now, I need git to ignore this file while still being able to keep the one in the remote repository untouched when I git push the remaining files.

I've added the file to .gitignore and .git/info/exclude but it is still being traced when I run git status. I could simply run git add . and afterwards remove the unwanted file, but this is unpractical and bothersome.

I'm relatively new to git, so I thank you for your time and your patience.

IronJoo
  • 11
  • Does this answer your question? [How to stop tracking and ignore changes to a file in Git?](https://stackoverflow.com/questions/936249/how-to-stop-tracking-and-ignore-changes-to-a-file-in-git) – AD7six Mar 25 '21 at 08:24
  • I've linked to the canonical duplicate, but the correct solution is as outlined by bk2204 below - to not track files that must be edited. More generally: do not store config in the same repo as the code, https://12factor.net is a possibly useful reference. – AD7six Mar 25 '21 at 08:27

1 Answers1

2

As outlined in the Git FAQ, you cannot ignore changes to a tracked file. People often suggest using one of the options to git update-index, but as outlined in the FAQ entry, that doesn't work.

The FAQ proposes a solution:

If your goal is to modify a configuration file, it can often be helpful to have a file checked into the repository which is a template or set of defaults which can then be copied alongside and modified as appropriate. This second, modified file is usually ignored to prevent accidentally committing it.

That's the best that you can do, and the recommended approach by Git developers. If you control the remote repository, you should make this change. If you don't, ask the owner to make this change and point them to the FAQ entry.

bk2204
  • 64,793
  • 6
  • 84
  • 100