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?
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 ).
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.
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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With