Currently I'm working with a team on a project. Due to some reasons my computer needs some special settings so I want to keep a local file different from git remote, which won't be uploaded when I git push. What should I do?
I guess I may need to do some modifications in .gitignore, but that will have a global effect.
CodePudding user response:
There's no solution for this built into Git.
One solution is to git stash
your locally-modified version of the file before merging or rebasing, and then restoring it after the merge:
# Stash your local changes
git stash -m 'Preserve local changes.' -- the-special-file.conf
# Merge, rebase, whatever you need to do
git pull
# Un-stash your local changes
git stash pop
You can package this up into a script or Git alias, but keep in mind that you run the risk of creating a conflict between your local version of the file and the remote version. You might have to spend a while resolving conflicts.
CodePudding user response:
Two common ways to have local settings described in a file, not shared with the repo:
have your whole config unversioned : instead of committing the config file, commit a template, place the config file in gitignore list, have each developper create a local config from template
have a way to load a local config file: add some way to say
include: config-local.conf
in your shared conf (which doesn't fail if file is missing), putconfig-local.conf
in gitignore list, overload configuration settings inconfig-local.conf
We're using the second option and are very happy with it.