cjr
cjr

Reputation: 33

how to update git branch created from github pull request with more recent changes

I'm experimenting with github fork-and-pull model playing a role of maintainer (full access to golden repo) and a role of contributor (who contributes by forking and creating a pull request).

GitHub has clear directions for the maintainer on how to create a local branch from pull request in order to review the code locally (i.e. build/test/etc): From your project repo:

git checkout -b pr-review-branch-name master
git pull [fork-url-from-pull-request]

So far so good. As maintainer, I comment on the PR, and ask for some additional work. The contributor goes ahead and makes the requested changes, pushes them up to his fork on the server (and updates the pull request message board)..

My question: as Maintainer, do I need to create a new branch as described above to pull the updated code in the pull request? Or is there a way for me to update the branch I already created above?

Update: here are my exact commands (with identity removed):

$ /c/ws/demo/maintainer
$ git clone https://server.xyz.com/PoCs/fork-and-pull-test.git
Cloning into 'fork-and-pull-test'...
Checking connectivity... done.

$ /c/ws/demo/maintainer
$ cd fork-and-pull-test/

$ /c/ws/demo/maintainer/fork-and-pull-test (master)
$ git checkout -b pr-review-branch-name master
Switched to a new branch 'pr-review-branch-name'

$ /c/ws/demo/maintainer/fork-and-pull-test (pr-review-branch-name)
$ git pull https://server.xyz.com/forker/fork-and-pull-test.git master
...
From https://server.xyz.com/forker/fork-and-pull-test
 * branch            master     -> FETCH_HEAD
Updating 57e8399..96cada4
Fast-forward
..

$ /c/ws/demo/maintainer/fork-and-pull-test (pr-review-branch-name)
$ git status
On branch pr-review-branch-name
nothing to commit, working directory clean

$ git remote -v
origin  https://server.xyz.com/PoCs/fork-and-pull-test.git (fetch)
origin  https://server.xyz.com/PoCs/fork-and-pull-test.git (push)

Upvotes: 0

Views: 1024

Answers (1)

charlesreid1
charlesreid1

Reputation: 4841

The person who forked your repository (who I'll call the "forker") has a remote clone, and they are committing to their feature branch. The pull request is simply you fetching changes from their remote repository, and then merging them to your local branch. (Note: Since a git pull is the same as git fetch && git merge, you might think of a "Pull Request" as a "Fetch & Merge Request".)

If you've already pulled from the forker's repository (assuming their remote is called "forker"), you probably ran a command like this:

git remote add forker https://github.com/forker/myrepo.git

already have a local copy of the branch, and that branch has a remote associated with with the forker's remote repository.

If you run git remote -v you should see the forker's repository:

$ git remote -v
origin      [email protected]:me/myrepo.git (fetch)
origin      [email protected]:me/myrepo.git (push)
forker      [email protected]:forker/myrepo.git (fetch)
forker      [email protected]:forker/myrepo.git (push)

Then you can run git pull forker pr-review-branch-name to update your local branch pr-review-branch-name with their latest commits. There's no need to create a new branch each time they update their branch.

Upvotes: 1

Related Questions