I’ve been experiencing a particular problem with git
at a new project that I was added to as a collaborator. Here’s what I usually do:
- Create a new branch from
develop
in order to fix a bug:
$ git checkout develop && git pull origin develop && git checkout -b NEW_BRANCH_1
- After making changes, I push them to the repository:
$ git add . && git commit -am 'some-message' && git push origin NEW_BRANCH_1
- While I wait for a code review, I create another branch for another bug fix:
$ git checkout develop && git pull origin develop && git checkout -b NEW_BRANCH_2
- I make and push changes:
$ git add . && git commit -am 'another-message' && git push origin NEW_BRANCH_2
At the moment, it’s only me creating PRs.
Now onto the problem. After receiving successful code reviews, I first merge NEW_BRANCH_1
into develop
with the fast-forward
algorithm. After a successful merge, I then subsequently try to merge NEW_BRANCH_2
into develop
, but then am faced with the following error:
The merge could not be completed because the repository is configured to require fast-forward merges and the target branch contains commits which are not present in the source branch. To perform this merge, either merge
develop
intoNEW_BRANCH_2
, or rebaseNEW_BRANCH_2
ontodevelop
With this, I’m forced to select the option rebase and fast-forward
.
How can I avoid this? I kind of understand that NEW_BRANCH_2
doesn’t have the commit from NEW_BRANCH_1
, but there’s got to be some approach to this that’ll avoid rebasing. At any point, I could have up to 10 open PRs, all waiting for a code review, and checking out into each of these bug fix branches and running git pull origin develop --rebase && git push origin <BRANCH_NAME>
can become cumbersome.