This might be a duplicate question, but I couldn't figure out how can I go about it. I'm trying to merge a remote branch say remoteBranch which is not a master branch to my local branch localBranch.
One of my developer added a new branch for an api end point on remote branch remoteBranch. As a frontend developer, I need to fetch that branch and merge it with my local development branch localBranch to make use of that api end point. How can I do this?
Simply merge it.
git fetch
git checkout localBranch
git merge remoteBranch
According to the documentation of git-merge you can merge any other branch with your local branch.
Your current branch has to be your localBranch. To merge the remote branch simply type:
git merge remoteName/remoteBranch
In this case I assumed the name of your remote that contains the branch you need to be called remoteName. It may be called differently like origin or upstream. You need to make sure that your local reference to the remove branch is up to date. So perform a fetch command before doing the merge like so:
git fetch remoteName
Does this help you?
To merge remoteBranch into localBranch
git fetch
git merge localBranch remoteName/remoteBranch
where remoteName is probably "origin", you can find that by git remote -v
However, sometimes you may want to rebase (re-writing history to keep sequence of commits "clean") instead of merge (which also adds a merge commit)

You can rebase a remoteBranch into a localBranch using:
git fetch
git checkout localBranch
git rebase remoteName/remoteBranch
ref: https://www.atlassian.com/git/tutorials/merging-vs-rebasing
Can use the following too, to achieve same:
git pull origin origin-branch-name:local-branch-name
above will merge the origin branch with local branch, keeping active intact
git pull another-local-branch:another2-local-branch
it should (not tested) merge the two different branches while keeping active intact
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