Search code examples
gitgitignore

git - do not push local changes, but receive remote changes in new branch


This may already have an answer; I'm just not sure how to search for it.

Here's my situation: I have a repo that has a configuration file in it called environments.json. There are changes I need to make to this file when working locally that I don't want to commit or get pushed back to the origin. OK, fine; that's what git ignore is for.

But when I set that up, it also means that when I pull a new branch from origin, I don't get any updates made by others to that file. On a daily basis, that isn't an issue, but every so often a new environment object may be added to the file (a new AWS instance, for example), and I do need to get that info.

So my question is: how can I set up git so that when I commit and push my repo, it does not include any changes I've made to environments.json, but when I do a pull, or get a new branch, I do receive changes to the file that others have made and pushed to origin (even if they overwrite my local changes)?


Solution

  • Put the name of the file in .git/info/exclude

    This file does not get committed back to the remote repo and will prevent changes to noted files from being staged.

    I imagine from time to time this will result in conflicts but they should be easy enough to manage.

    https://help.github.com/articles/ignoring-files/#explicit-repository-excludes