My previous Git article may not be a perfect solution to handle local configuration problem. Especially if you checkout / reset often, chances are your local configuration may be overwritten, or you cannot checkout / reset because Git knows you have indeeed changed something.

Private Branch Pattern

You may try Private Branch Pattern instead. See the details below.

0. Set Up

You are now working on your master branch. You would like to add your local configuration. So you create a branch (say, local-config) for it.

git checkout -b local-config

Then you commit your configuration and also create your feature branch at local-config branch for your new changes (by git checkout -b).

The tree now looks like:

M (master)
 \
  L (HEAD -> feature, local-config)

1. Make changes

Then you make changes and commit them. The tree now looks like:

M (master)
 \
  L (local-config)
   \
    A---B---C (HEAD -> feature)

2. Rebase to master

Now you want to add your change to master branch, but you realized that your changes are based on your local config (L).

So you would like to move your changes to master branch but leaving local-config behind. You may run:

git rebase --onto master local-config

Then the tree becomes:

M (master)
|\
| A'---B'---C' (HEAD -> feature)
 \
  L (local-config)

3. Wrap things up

Now you can set master to feature, or merge the branches, so that your master branch has the feature changes with no local changes.

Then you can tidy up the 3 branches (e.g. rebase local-config to master branch) to continue your development.


Reference: