Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git merge other branch into another branch?

Tags:

git

Is it possible to merge other branch into another branch?

For example, I'm in branch1 and want to pull remote/develop into develop branch and then merge develop into current branch1.

What am I doing is checkout develop(maybe stash first), pull, checkout branch1 and then merge develop.

Is it possible to do all these with switch to develop branch ?

like image 983
Sato Avatar asked Dec 16 '13 05:12

Sato


3 Answers

What you are doing is the right thing.

git checkout develop
git pull
git checkout branch1
git merge develop

I don't if you are asking for a shorthand for these commands or what, but this is the sequence I always use.

like image 88
amahfouz Avatar answered Sep 28 '22 02:09

amahfouz


A slightly quicker option would be to (while on branch1):

git fetch
git merge remote/develop

This will get your remote/develop merged into branch1, however it should be noted that your local develop branch won't be updated.

like image 24
Nick Avatar answered Sep 28 '22 01:09

Nick


A simple option would be to (while on branch1):

git fetch origin develop:develop
git merge develop

This will fetch develop from the remote origin and point your local develop branch to it, and then get your (now updated) local develop branch merged into branch1.

In case your local develop has diverged from the remote and you want to replace it with what's in the remote, then use --force to tell Git to override your local develop

git fetch origin develop:develop --force
git merge develop
like image 44
C. Augusto Proiete Avatar answered Sep 28 '22 02:09

C. Augusto Proiete