4

I am forking from

which results in

  • github.com/MYACCOUNT/mantisbt

from where I clone it and checkout the branch (I am interested in) to my local machine.

My issue is that I would like to fetch the latest branch (master-1.2.x) from the remote repository (mantisbt/mantisbt) and merge it under the same branch the to my local repository.

Which would result in something like

  • git fetch remote-repo-branch
  • git merge remote-repo-branch/local-branch

How is this done?

UPDATE:

content is fetched with

  • git fetch upstream master-1.2.x

and merged to currently checked out branch with

  • git merge origin/master-1.2.x
udo
  • 4,832
  • 4
  • 54
  • 82
  • Possible duplicate of [Git: Merge a Remote branch locally](https://stackoverflow.com/questions/21651185/git-merge-a-remote-branch-locally) – Michael Freidgeim May 30 '17 at 06:12

2 Answers2

8

Github has an example of exactly this in their "fork a repo" help documentation.

git remote add upstream git://github.com/mantisbt/mantisbt 
// Assigns the original repo to a remote called "upstream"
git fetch upstream
ptomli
  • 11,730
  • 4
  • 40
  • 68
  • I tried that (before asking here) but when you clone, only the master branch is "created" and "updated" by "fetch" and "merge". Branches are not affected and remain on the revision when the remote repo was forked. – udo Nov 19 '11 at 19:42
  • You just need to specify the name of the upstream branch you want to pull. There are a few other questions on SO for this. http://stackoverflow.com/questions/67699/how-do-i-clone-all-remote-branches-with-git http://stackoverflow.com/questions/1709177/git-pull-certain-branch-from-github. Basically `git fetch upstream other-branch` – ptomli Nov 20 '11 at 17:52
0

What just no worked for me (git version 1.7.9.5 and using HTTPS protocol):

Originally I forked "foobar.git" from "their account" to "my account":

their_account/foobar.git => my_account/foobar.git

The branch of interest is "baz"

I worked and made commits on "baz" and they did too. I wanted to merge their commits with mine. As ptomli suggested above, I did:

$ git checkout baz
$ git fetch https://github.com/their_account/foobar.git baz
Username for 'https://github.com': my_account
Password for 'https://my_account@github.com': 
remote: Counting objects: 189, done.
remote: Compressing objects: 100% (109/109), done.
remote: Total 189 (delta 92), reused 151 (delta 76)
Receiving objects: 100% (189/189), 107.77 KiB, done.
Resolving deltas: 100% (92/92), done.
From https://github.com/their_account/foobar
 * branch            baz -> FETCH_HEAD

The step that I did not see noted was:

$ git merge FETCH_HEAD

and the two branches were merged.

bhfailor
  • 175
  • 2
  • 6