git rebase onto remote updates

痞子三分冷 提交于 2019-11-29 21:36:56

Do you know about git pull --rebase? It rebases rather than merging when you pull, and prevents merge commits from polluting your history.

You can also set it up as the default behaviour for a branch with the branch.<name>.rebase and branch.autosetuprebase config options.

I have found, over time, my favorite solution is:

git checkout topic
# make [n] commits
git rebase -i HEAD~[n] #clean up time
git checkout master
git pull --rebase
git checkout topic
git rebase master
git checkout master
git merge topic
git push origin

For our team we set something up which works very well and does not use rebase at all.

We cut our work in Jira tickets which do not take too long, typically 1-2 days effort. Each dev creates a branch per ticket and works on this branch. When ready to share this is pushed to the central server.

The central server is monitored by a hudson CI server which pulls the changes, merges all updated branches, rebuilds the software, runs the tests and pushes everything to the central master git repository.

From there we pull it back to our repositories. We do regularly (i.e. every couple of days) merge our working branches with the central master to keep them 'close'.

Since nobody is working on the 'merging' machine and nobody other than the CI server touches the master, we have very infrequently merging issues (in about 1-2% of the commits). And these are quickly resolved on the build server by cleaning the workspace. We found we could have avoided most of these by keeping the branches short and merging with the remote master before pushing.

I also fond that merging is much more robust than rebasing and requires a lot less of rework.

You can also just rebase against the up-to-date master

git checkout topic_1
git rebase refs/remotes/origin/master

Which obviates the need for the pull (at least until the EOL of your feature branch). Our process uses GitHub pull requests so I never need to do that locally.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!