Merging pull requests together

Say if you have 3 pull requests A,B,C which are on three branches bA,bB,bC. and your main branch is master.

First get all of his branches to your local repo without merging it.
git fetch his-repo

so now your repo may have four branches: master, bA, bB, bC

I will create a branch from master called f-merge-his-repo

git checkout master
This makes sure that f-merge-his-repo branches out from master.

git checkout -b f-merge-his-repo
This creates the branch f-merge-his-repo and switch to it.

So now you are currently on f-merge-his-repo, use the following commands:

git merge bA

git merge bB

git merge bC

If there are conflicts you should fix it(manually or using a mergetool), but as you said there are no conflicts, so we say that bA bB and bC are now all in f-merge-his-repo

then, just simply merge f-merge-his-repo into your master branch

You should first switch to the master branch.
git checkout master

And then merge f-merge-his-repo
git merge f-merge-his-repo

or if you prefer a none fast forward merge
git merge --no-ff f-merge-his-repo

After all, delete these branches.

git branch -d bA

git branch -d bB

git branch -d bC

git branch -d f-merge-his-repo

You should really take a look at pro-git here. It is a simple book which shows you everything you need with git in your daily work, and believe me, once you get used of git bash, you will find all of these git GUI’s frustrated(except viewing the log, I use gitk to view and analyse the log)

Last tip:

A good way to remember git merge and git rebase is like

Merge is merging another branch TO your current branch (of course you can name both branches, but the default syntax is merge the branch to your current branch)

so you should always switch to the main branch and merge others branch

git checkout master

git merge their-branch --no-ff
or
git merge their-branch

And rebase is rebasing your current branch ON another branch(usually the main branch)

git checkout feature-branch

git rebase master

Leave a Comment

tech