Git merge two local branches

GitMerge

Git Problem Overview


I have branch Master, branchA and branchB. Now I'm working in the branchA and I need to merge branchA with branchB and proceed my work in the branchA. All files are comitted in the branchA and branchB.

What's the fast way to implement it?

Git Solutions


Solution 1 - Git

If I understood your question, you want to merge branchB into branchA. To do so,

first checkout branchA like below,

git checkout branchA

Then execute the below command to merge branchB into branchA:

git merge branchB

Solution 2 - Git

Here's a clear picture:

Assuming we have branch-A and branch-B

We want to merge branch-B into branch-A

on branch-B -> A: switch to branch-A

on branch-A: git merge branch-B

Solution 3 - Git

The answer from the Abiraman was absolutely correct. However, for newbies to git, they might forget to pull the repository. Whenever you want to do a merge from branchB into branchA. First checkout and take pull from branchB (Make sure that, your branch is updated with remote branch)

git checkout branchB
git pull

Now you local branchB is updated with remote branchB Now you can checkout to branchA

git checkout branchA

Now you are in branchA, then you can merge with branchB using following command

git merge branchB

Solution 4 - Git

on branchB do $git checkout branchA to switch to branch A

on branchA do $git merge branchB

That's all you need.

Solution 5 - Git

If you or another dev will not work on branchB further, I think it's better to keep commits in order to make reverts without headaches. So ;

git checkout branchA
git pull --rebase branchB

It's important that branchB shouldn't be used anymore.

For more ; https://www.derekgourlay.com/blog/git-when-to-merge-vs-when-to-rebase/

Solution 6 - Git

For merging first branch to second one:

on first branch: git merge secondBranch

on second branch: Move to first branch-> git checkout firstBranch-> git merge secondBranch

Solution 7 - Git

I would recommend below one if anyone looking to fetch remote changes as well:

git pull
git merge origin/development

Solution 8 - Git

It is very simple, you need to first checkout to branchA, for this you can use command git checkout branchA. Now you are in branchA, just hit the merge command git merge branchB. And you are done!!!

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser3127896View Question on Stackoverflow
Solution 1 - GitAbimaran KugathasanView Answer on Stackoverflow
Solution 2 - GitMahmoud ZaltView Answer on Stackoverflow
Solution 3 - Gituser12057507View Answer on Stackoverflow
Solution 4 - GitDapo MomoduView Answer on Stackoverflow
Solution 5 - GitErdinç ÇorbacıView Answer on Stackoverflow
Solution 6 - GitHimanshu GuptaView Answer on Stackoverflow
Solution 7 - GitAlok GuptaView Answer on Stackoverflow
Solution 8 - GitS.RView Answer on Stackoverflow