Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I sync all new upstream branches with my fork?

Tags:

git

github

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.

like image 865
Gabriel Avatar asked May 07 '18 18:05

Gabriel


People also ask

How do I sync a fork with the upstream repository?

Here are some notes on syncing a fork with the upstream repository. Configure a remote upstream that points to the upstream (original) repository in Git. This is needed to sync changes you make in a fork with the original repository.

How do I apply changes from upstream to local branch?

You're going to apply changes from upstream to local first, and then push them to origin after that's done. To get the changes from the upstream repo, you need to fetch them (and specify the remote). Now check out your master branch and merge the upstream master into it:

How to update a GitHub fork from the user branch?

If you are using GitHub for Windows or Mac then now they have a one-click feature to update forks: Select the repository in the UI. Click "Update from user/branch" button the top. Actually, it is possible to create a branch in your fork from any commit of the upstream in the browser:

Why do I need to add a remote to sync my fork?

Before you can sync, you need to add a remote that points to the upstream repository. You may have done this when you originally forked. Tip: Syncing your fork only updates your local copy of the repository; it does not update your repository on GitHub.


Video Answer


1 Answers

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.

like image 194
VonC Avatar answered Nov 15 '22 08:11

VonC