Home > Enterprise >  Merging multiple branches in Git
Merging multiple branches in Git

Time:01-21

I have a repository. From the main branch i have created branches as in the illustration. Also before making any changes to the branches, I've made 3 commits to the main branch. After completing changes with main branch, I've branched 2 more branches from BranchA in a transitive fashion. Now i want to merge the Branches A,B and C to main branch. Is it possible to do?

I have a repository. From the main branch i have created branches as in the illustration.
Also before making any changes to the branches, I've made 3 commits to the main branch.  After completing changes with main branch, I've branched 2 more branches from BranchA in a transitive fashion.  Now i want to merge the Branches A,B and C to main branch.  Is it possible to do?

CodePudding user response:

Make sure those commits in main branch are pushed to remote. Merge branch C to branch B, then merge Branch B to Branch A. Remote main branch have some commit updates that are not in your local repository. So, checkout to main branch and apply git pull origin main. Now, checkout to branch A. rebase master onto your current branch. git rebase main Resolve if any conflict arises and complete the rebase operation. Force push your branch to remote. Finally, merge branch A with main.

CodePudding user response:

Given branchC is on top of branchB which is on top of branchA, you could get it all in by just merging branchC into main. You could just as well merge each one after the other, first branchA, then branchB, then branchC but it would be the same result in terms of content... so, it really depends on what you would like your history to look like:

* merging branchC <- (main)
|\
| * 3rd commit branchC <- (branchC)
| * 2nd commit branchC
| * 1st commit branchC
| * 3rd commit branchB <- (branchB)
| * 2nd commit branchB
| * 1st commit branchB
| * 3rd commit branchA <- (branchA)
| * 2nd commit branchA
| * 1st commit branchA
* | commit 3
* | commit 2
* | commit 1
|/
* initial commit

Or

* merging branchC <- (main)
|\
| * 3rd commit branchC <- (branchC)
| * 2nd commit branchC
| * 1st commit branchC
* | Merging branch B
|\|
| * 3rd commit branchB <- (branchB)
| * 2nd commit branchB
| * 1st commit branchB
* | Merging branch A
|\|
| * 3rd commit branchA <- (branchA)
| * 2nd commit branchA
| * 1st commit branchA
* | commit 3
* | commit 2
* | commit 1
|/
* initial commit

  • Related