gitgit-branchgitignoregit-stash

How to apply local changes to git repo after every pull from master without ever pushing to master


My development setup is quite different to the other developers in the team - mac vs linux - docker vs vagrant

Every time I pull a new branch I have to make a load of changes to config files and docker related files to get my dev environment functioning.

I need to avoid pushing these to my working branches as they can't be merged into master.

At the moment I am leaving these files off git add and then manually adding them back every time I switch branches and perform a pull.

The following SO question suggests I could git stash and then git stash apply How to keep the git local changes without commit and apply to different repos after switch

I think that would work providing I keep my git stashes neat and the last one is restricted to my dev changes. I'm wondering if there is a better way to handle this workflow.

Can I save these changes in a dev-setup branch and use in a similar way to the stash method?


Solution

  • One solution could be to add theses files to your locally ignored files. It is located at .git/info/exclude.
    It works the same way as the usual .gitignore (see https://git-scm.com/docs/gitignore).

    If the files are updated on the upstream, you will not see any modifications on the local files after a pull. And you will not be able to commit any changes to theses files until you remove them from this exclude file.