Background: We use github for our project and I work on my own fork of our main repository. We use rebase instead of merge to avoid large merge commits.
Scenario: The way I want to work is like this:
Problem: Step 4 is where I get the problems. I almost always have to deal with non-fast-forwarded commits and use git push --force.
I've looked at
Git: how to maintain permanent parallel branches
How to maintain (mostly) parallel branches with only a few difference
and haven't found a way to make my workflow work. Doing a google search on git workflows mostly returns results that assume that you all work on local branches and don't keep a remote copy on github (e.g. http://nvie.com/posts/a-successful-git-branching-model/).
I'm relatively new to Git, so I'd like to know if I am missing something here. I'd like to be able to do step 4 without a --force. An alternate workflow that still allows me to use rebase instead of merge and keep a remote copy of my local branch would also be very useful.
At this point you should not rebase your work. You should create 'rework' commits and update your feature branch. This helps with traceability in the pull request, and prevents the accidental history breakage. Review is done and ready to be integrated into the target branch.
If you need to update a feature branch, always choose to rebase for maintaining the branch history clean. It keeps the commit history out of the branch, contrary to the git merge command, which is its alternative.
No, locally rebasing doesn't change the remote.
git push --force
is a fact of life when dealing with rebase and remote branches, because git push
won't do a non-fast-forward push without it. Most things in git assume that history is only appended to, never edited, and rebase breaks that assumption, so you have to do some pretty wonky things to make it work.
We used to use a rebase workflow very similar to the one you describe, but eventually switched back to a merge workflow after a while. Rebasing gives you a nice, pretty, linear history, but has many drawbacks, such as requiring --force
, losing the ability to see the state of a branch before you merge in master, et cetera.
As Amber mentions, rebase makes it very difficult to work with other people on the same branch -- before git push --force
ing, you have to look at the status of the remote branch to see if someone else has pushed to it first, and pull --rebase
that in, then git push --force
. Even this has a race condition - if someone else pushes just before you push --force
, their changes will get overwritten by yours.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With