Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merging 2 branches in one of the two or in a new branch

Tags:

git

merge

Lets say I am on a branch test-a and I create two new branches from a and do some individual commits to each one(to different files in each branch):

#in branch test-a
$git checkout test-a

#creating branch test-b and push a commit
$git checkout -b test-b
$git commit -a -m "initial commit in test-b"
$git push

#creating branch test-b and push a commit
$git checkout test-a
$git checkout -b test-c
$git commit -a -m "initial commit in test-c"
$git push

Now how can I merge test-b with test-c in one branch, either test-b or test-c or in a new branch merged-b-c branch? (not merged with test-a)

this is the usage of merge command in my case?:

$git checkout test-b
$git merge test-c
like image 414
Mpizos Dimitris Avatar asked Dec 18 '22 05:12

Mpizos Dimitris


1 Answers

If you want the changes in a separate branch, then just fork out a new one from one of them, and the merge the another.

git checkout test-b
git checkout -b test-b-c
git merge test-c

Otherwise, if you don't mind updating the existing branches, the way you have merged would work too. As an additional pointer, if you are individually using the branch, and want to maintain linear history you can use rebase too.

git checkout test-b
git rebase test-c
like image 58
hspandher Avatar answered Dec 27 '22 18:12

hspandher