ShaneTheKing
ShaneTheKing

Reputation: 725

Is it possible to have a local file that's different from its remote counterpart on Github?

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?

Upvotes: 1

Views: 77

Answers (2)

dcastro
dcastro

Reputation: 68640

You can use --assume-unchanged

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

Git will ignore any further changes to this file.

Upvotes: 4

Carlos Martín Nieto
Carlos Martín Nieto

Reputation: 5277

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.

Upvotes: 2

Related Questions