How can I merge these two branches?

66 Views Asked by At

enter image description here

First of all, I just started to learn git.

I want to merge the red branch into the others, but there is no merge button.

In fact, essentially, I don't know why they are seperated.

enter image description here

1

There are 1 best solutions below

1
Hujaakbar On BEST ANSWER
  1. open the terminal, (it can be standalone terminal or VSCode's inbuilt terminal , doesn't matter).
  2. Check what branch you are in currently using git status command. If you are not on the branch you want to merge into (i.e. receiving branch), switch to that branch using git switch [branchname] eg. git switch main
  3. then merge the branch using git merge [branchname] eg. git merge featureA

I don't know why they are seperated.

In your case, the red branch is orphan branch, that's why it is separate. In short, orphan branch doesn't share the same ancestor as other branches. You can google for more detailed information. To merge orphan branch, you should add the following flag --allow-unrelated-histories to git merge command. eg. git merge featureA --allow-unrelated-histories

Above steps merge the branch named featureA into main branch

Here is a good article if you want to learn more about merging.

Note:

A. before merging make sure all the changes are committed.

B. beware Merge conflict may arise. In that case this article might help