Merge two remote branches in a Git repository

79,021

Solution 1

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

Solution 2

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.

Share:
79,021

Related videos on Youtube

Sai Ye Yan Naing Aye
Author by

Sai Ye Yan Naing Aye

A java developer who loves simplicity.Currently a software engineer at SandBox Technology, Singapore.

Updated on March 31, 2021

Comments

  • Sai Ye Yan Naing Aye
    Sai Ye Yan Naing Aye about 3 years

    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?

  • Sai Ye Yan Naing Aye
    Sai Ye Yan Naing Aye over 9 years
    First do I clone production branch?
  • Sai Ye Yan Naing Aye
    Sai Ye Yan Naing Aye over 9 years
    @ charlierproctor you right but i have some files, these are both changes and not merge.Any suggestion?
  • charlierproctor
    charlierproctor over 9 years
    It sounds like you are running into merge conflicts. Unfortunately, you need to manually resolve these issues. Open up the files where the conflicts occur and manually resolve the conflicts. When you're done, add and commit.
  • charlierproctor
    charlierproctor over 9 years
    Yea no problem. Best of luck.