Reputation: 1751
Sometime ago I forked a git repo. Since then there has been several new commits to the master branch. https://help.github.com/articles/syncing-a-fork/ explains how to sync the upstream master branch with the local master branch and then push those commits to my fork.
However it does not mention how to sync new upstream branches. When I originally forked the project on github it looks like it brought over all of the then current branches.
I've seen explanations on how to sync one branch at a time. Is there any way to sync all of the branches new and old all at once?
I haven't made any commits to my fork. Thus I am looking for a fast forward sync.
Edit: Another way to say this:
I want
git ls-remote origin
to match
git ls-remote upstream
This would include branches and tags.
Upvotes: 14
Views: 15255
Reputation: 1323363
However it does not mention how to sync new upstream branches
All you need to do is:
git fetch upstream
It supposes you have a remote repository referenced as upstream
.
If not:
git remote add upstream <upstream_url>
That will fetch or update all the upstream branches and store them in your local repo, in the upstream namespace.
You can see those branches with:
git branch -avv
it it doesn't let me push all of the upstream branches to origin.
For that, you need to make a local branch based on any upstream branch you want to push to origin:
git branch abranch upstream/abranch
gut push -u origin abranch
See more at "git - create local branch from existing remote branch".
To do so for all branches, see "Pull all branches from remote through it's mirror bare remote".
Or, better: "Track all remote git branches as local branches".
Simply use "upstream
" instead of origin
.
Upvotes: 14
Reputation: 335
Do the following:
List all your remote repositories to confirm if you have an upstream (parent/original) repository there or not:
git remote -v
If you don't see the original remote repository, add it by typing the command below. This is normally called 'upstream' unlike 'origin' which would be your forked remote repository.
git remote add upstream <path of the original remote respository>
Verify it's added as remote called 'upstream' and confirm it listed for both 'fetch' and 'push' operations.
git remote -v
Fetch the newly (after your fork) created branches locally:
git fetch upstream
List all the branches to confirm that you can see newly created branches
git branch -a
Now you can locally check out the branch to work on it as needed.
Upvotes: 2