1

I was wondering if it is possible to have a file on your local machine that is different from the remote version of the file.

For example, if I wanted a config file locally to have actual server and port settings, but I wanted the version of the file on Github to have "default" settings, and for any new changes to the config file to be ignored.

Does anyone know if this is possible?

ShaneTheKing
  • 725
  • 5
  • 18
  • 1
    possible duplicate of [Prevent local changes getting pushed in Git](http://stackoverflow.com/questions/2173726/prevent-local-changes-getting-pushed-in-git) – David Ogren Apr 04 '14 at 15:55

2 Answers2

4

You can use --assume-unchanged

git update-index --assume-unchanged [filepath]

Git will ignore any further changes to this file.

dcastro
  • 66,540
  • 21
  • 145
  • 155
  • 1
    This does not untrack the file. This is a promise to git that the file won't change on disk, which is a lie; and the flag may be reset by any later command that touches the index. – Carlos Martín Nieto Apr 04 '14 at 16:04
  • Thank you! I'm marking this as the answer because it answers my actual question, but I appreciate Carlos's response as well because it's the more "proper" solution. So thank you both. – ShaneTheKing Apr 04 '14 at 16:11
  • The rephrased answer still misses the bit that it could be undone by a later command at any point. – Carlos Martín Nieto Apr 04 '14 at 17:25
2

If the file is never changed by anybody else (and never run git commit -a), you can keep your modified version, but it will always show up in diffs and the status output. Once you track a file, you're telling Git that you care about it, so it will try to merge/update when you update the working directory.

The usual recommendations for this kind of situation is have a config.sample file (assuming config is the where the app reads the configuration from) where you store the defaults, and have every user rename that to config and set their own configuration.

Alternatively, have the config file include a config.local that overrides the default settings, if that's something the config language allows.

This usually would also make testing and deployment simpler by not having tracked files that change between uses, and would make the deployment/installation scripts much less likely to overwrite a user's local configuration.

Carlos Martín Nieto
  • 5,207
  • 1
  • 15
  • 16