Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merge two remote branches in a Git repository

I have one remote repository with many branches. For example, my repository name is:

http://navis.com/MyRepo.git 

Its branches are:

development production (master) testing 

I would like to merge the development branch into the production (master) branch. Can anybody share a Git command for merging two remote branches?

like image 736
Sai Ye Yan Naing Aye Avatar asked Jan 27 '15 04:01

Sai Ye Yan Naing Aye


People also ask

How do I merge branches in remote repository?

The idea here, is to merge "one of your local branch" (here anotherLocalBranch ) to a remote branch ( origin/aBranch ). For that, you create first " myBranch " as representing that remote branch: that is the git checkout -b myBranch origin/aBranch part. And then you can merge anotherLocalBranch to it (to myBranch ).

How do I merge 2 branches in git?

Merging Branches in a Local Repository To merge branches locally, use git checkout to switch to the branch you want to merge into. This branch is typically the main branch. Next, use git merge and specify the name of the other branch to bring into this branch.

How do I merge remote branch remote master?

First we run git checkout master to change the active branch back to the master branch. Then we run the command git merge new-branch to merge the new feature into the master branch. Note: git merge merges the specified branch into the currently active branch. So we need to be on the branch that we are merging into.


2 Answers

If you have remote-tracking branches set up locally, it's as simple as:

git checkout production git merge development git push origin production 

If you have not yet set up remote-tracking branches, you could do something like:

git fetch origin git checkout production     # or `git checkout -b production origin/production` if you haven't set up production branch locally git merge origin/development git push origin production 
like image 153
charlierproctor Avatar answered Sep 24 '22 19:09

charlierproctor


you can do this like:

git pull origin development:temp git push origin temp:production 

Why a temp branch is need and you should not to use the local development? Because your local development may not be the same as the remote one.

like image 31
zizhen zhan Avatar answered Sep 21 '22 19:09

zizhen zhan