简体   繁体   中英

Merge three github branches locally

Currently I have a scenario where I want to locally merge two branches to a third branch. So the scenario is. FYI I am a noob in github.

  1. Master --> Epic_1
  2. Master --> Epic_2

Now I want to merge Epic_1 branch first to Master and then merge Epic_2 branch to master on top of merged Epic_1 and Master. I am not sure what to search for to get proper answer so adding this question. IMPORTANT - I want all of this to be done locally only and nothing should go to remote branch.

Thanks, Ray

git checkout master   # go to master since that’s your target branch
git merge Epic_1      # merge in the first branch
git merge Epic_2      # merge in the second branch

This will give you a result that looks approximately like this:

            (old) master      master (after merges)
                    ↓           ↓
* -- * -- * -- * -- * -- M1 -- M2
                       /      /
* -- * -- * -- * -- * -      /
                    ↑       /
                  Epic_1   /
                          /
* -- * -- * -- * -- * -- *
                         ↑
                       Epic_2

As with everything in Git, this happens only locally, so nothing on any of your remotes is affected. Of course, you can then push the master branch to update it on your remote.

You just

git fetch # in case these branches are from the remote and to be up-to-date

git checkout master

git merge branch_1

git merge branch_2

You can now do

git status

and

git log

to see the state of master. It will be local unless/until you explicitly push master to the remote (probably origin in your case).

If there are merge commits you'll need to resolve them but you'll get an appropriate message indicating that and that would be a separate question from this.

There are also lots of options with merges and rebasing and relevant topics like fast-forwarding but that is beyond the scope of this question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM