Muhammad Umer
Muhammad Umer

Reputation: 18147

Confused about git merge, how to merge master into branch but keep branches seperate

I've seen git merge name, git merge master name, and git merge. I'm confused what each command is doing.

Correct me if I'm wrong, does it matter which branch you're checked out at the time when you're merging, it seems it does.

Just to be sure I understand, tell me...

How can I merge branch a and branch b into one? What would new branch be a or b, how do you decide..

How can I merge branch a into master so its new master? (i.e. default merging)

How can I merge master to branch a so new changes in master are now present in branch a but they are still separate meaning if I commit on master it doesn't extend branch a?

Update

enter image description here

Upvotes: 0

Views: 1429

Answers (1)

Raghav
Raghav

Reputation: 580

"Does it matter which branch you're in at the time of merging?" Yes, it does.

"How can I merge branch a and branch b into one?"

If you want to merge your changes in branch b onto branch a, you should checkout to (git checkout branch_a) and then do git merge branch_b You will then be in branch_a and your changes in branch_b will be merged on to branch_a. (Note that your changes in branch_a will not be reflected in branch_b).

"How do I decide?"

For example, if you want to merge your feature branch (say, branch_a) changes on to your local master branch, you should checkout to master branch and merge branch_a by the method I have mentioned above.

"How do I merge my master branch changes onto a new branch?"

Say you have to merge your master branch changes on to branch_new, you should first pull your remote branch changes on to your local master using

git pull <remote_name> master:master

and then checkout to your new_branch using

git checkout new_branch

Then, you need to merge using

git merge master

Upvotes: 3

Related Questions