Today I was be asked by my colleague "How to maintain (Git) commits which is local only such configurations?".
Commits like these should always be with the development branch, however, we don't want them to be pushed back to repo.
The simplest way is to put those file paths in
.gitignore file - a text file indicates Git to ignore files from revision tracking. However, sometimes we can't just ignore them from revisioning, ex:
config.php. We need them to be tracked by Git, and also part of the changes stay in local at the same time.
For this circumstance, I'll maintain two branches locally, one is
master and another is
config. Both of them are setting upstream to
origin/master, but the
config branch will never push commits back to repo, instead, it pulls only. And the
config branch is always leading some commits which you don't want them to be pushed back.
For further explaination, let's create the
config branch and set the its upstream to
And the history tree will looks like this after checked-in several local commits.
The local commts may contain the necessary configurations which make your development enviroment works, so we coding/developing on the branch
config. This is the tree graph it looks like after we've done some works. (remember we still on branch
config which contains both local commits and works)
Now, assume we've done some works (
w1), and want then to be pushed back to repo. Here is the instructions: checkout the
master branch, pick up the works we've done from
config branch (NOTE: be avoid the local commits), then push them back.
config branch and pull again.
Finally we got works to be pushed back and local commits still stay in local.