Updating a feature branch to the actual state of the upstream main branch can be troublesome. Here is a workflow that works – at least for me.
Developing with Git is amazing, due to the possibilities to work with feature branches, remote repositories and so on. However, at some point, after some hours of development, the base of a feature branch will be outdated and it makes sense to update it before a pull request is send upstream. This is best done via rebasing. Here is a short work flow for a typical feature branch rebase I often need when developing for example Ansible modules.
- First, checkout the main branch, here devel.
- Update the main branch from the upstream repository.
- Rebase the local copy of the main branch.
- Push it to the remote origin, most likely your personal fork of the Git repo.
- Check out the feature branch
- Rebase the feature branch to the main branch.
- Force push the new history to the remote feature branch, most likely again your personal fork of the Git repo.
In terms of code this means:
$ git checkout devel $ git fetch upstream devel $ git rebase upstream/devel $ git push $ git checkout feature_branch $ git rebase origin/devel $ git push -f
This looks rather clean and easy – but I have to admit it took me quite some errors and Git cherry picking to finally get what is needed and what actually works.