How to update a local branch of a forked project?
-
03-07-2021 - |
Question
I cloned a forked github repo , created a branch out of it . How do I update ( with git pull ) my branch with upstream/master ?
In detail , here's what I did :
1) Forked a repo on GitHub
2) Cloned my github repo to local box
Then I made some local changes , committed and pushed to my GitHub repo . These changes were specific to me , and would not be useful to others , hence no Pull Request . I'll call these commits "private commits" . So this is what happened : 4) Did some "private commits"
Then I started working on one feature , which would be really useful to others . So I thought I'll have to branch out of my local master , before "private commits" , call it "pull-request-branch" . So , here's what I did :
5) git branch <before private commits>
6) git checkout -b pull-request-branch
7) git push -u origin pull-request-branch
Then I figured I'll have to update this branch with the Upstream changes before I start working on the new feature . So here's what I did next
8) git remote add upstream <original-repo>
9) git pull upstream pull-request-branch
( This does not work )
How do I update pull-request-branch with upstream/master ?
Solution
You specify the branch you want to pull from, not to:
$ git checkout pull-request-branch
$ git pull upstream master
will update pull-request-branch
from upstream/master
.
OTHER TIPS
I'd suggest having a local pull-request-branch
, merge --rebase
from upstream/master
into it, and then push to the remote pull-request-branch