Git: Merge a Remote branch locally

I’ve pulled all remote branches via git fetch --all. I can see the branch I’d like to merge via git branch -a as remotes/origin/branchname. Problem is its not accessible. I can’t merge or checkout?

  • git - get all files that have been modified in branch
  • git fails because of an untracked working tree file
  • How do I keep my branches up to date with the 'default' branch under Mercurial?
  • undo git pull of wrong branch onto master
  • Remove commits from a single branch in Git
  • Git fetch remote branch
  • Is Git's stashing mechanism essentially creating commit and then cherry-picking it?
  • How can I associate local unversioned code to git remote repository?
  • Git-windows case sensitive file names not handled properly
  • How to locally test a pull request from gitlab?
  • Disable auto-completion of remote branches in Git Bash?
  • Continue looping over submodules with the “git submodule foreach” command after a non-zero exit
  • 4 Solutions collect form web for “Git: Merge a Remote branch locally”

    You can reference those remote tracking branches ~(listed with git branch -r) with the name of their remote.

    If you want to merge one of those remote branches on your local branch:

    git checkout master
    git merge origin/aRemoteBranch

    If you want to merge one of your local branch on one of those remote branch, you need to create a local branch on top of said remote branch first:

    git checkout -b myBranch origin/aBranch
    git merge aLocalBranch

    Whenever I do a merge, I get into the branch I want to merge into (e.g. “git checkout branch-i-am-working-in“) and then do the following:

    git merge origin/branch-i-want-to-merge-from

    Maybe you want to track the remote branch with a local branch:

    1. Create a new local branch: git branch new-local-branch
    2. Set this newly created branch to track the remote branch: git branch --set-upstream-to=origin/remote-branch new-local-branch
    3. Enter into this branch: git checkout new-local-branch
    4. Pull all the contents of the remote branch into the local branch: git pull

    If you already fetched your remote branch and do git branch -a,
    you obtain something like :

    * 8.0
      remotes/origin/HEAD -> origin/8.0

    After that, you can use rep_mirror/8.0 to designate locally your remote branch.

    The trick is that remotes/rep_mirror/8.0 doesn’t work but rep_mirror/8.0 does.

    So, a command like git merge -m "my msg" rep_mirror/8.0 do the merge.

    (note : this is a comment to @VonC answer. I put it as another answer because code blocks don’t fit into the comment format)

    Git Baby is a git and github fan, let's start git clone.