How can I keep my fork in sync without adding a separate remote?

GitGithub

Git Problem Overview


Let's assume there is a repository someone/foobar on GitHub, which I forked to me/foobar.

How do I pull new commits from the parent repository directly to my fork, without having to add a separate remote and remember to pull regularly from there ?

The goal is to:

  • git pull to fetch from the parent repository
  • git push to send everything to my fork

Git Solutions


Solution 1 - Git

Open the forked Git repository me/foobar.

Click on Compare:

Here is a sample image of the page

You will get the notification: > There isn't anything to compare.
> someone:master is up to date with all commits from me:master. Try switching the base for your comparison.

Click on switching the base on this page:

Here is an example on the page

Then you get to see all the commits made to someone/foobar after the day you forked it.

Click on Create pull request:

Here is a sample page

Give the pull request a title and maybe a description and click Create pull request.

On the next page, scroll to the bottom of the page and click Merge pull request and Confirm merge.

Your Git repository me/foobar will be updated.

Edit: rebase options are shown here:

enter image description here

Solution 2 - Git

git remote set-url origin git@github.com:someone/foobar
git remote set-url origin --push git@github.com:me/foobar

There is one caveat though:
This is perfect if you are the only one making changes to your fork.
However, if it is shared with other people, you may have to pull from your fork, in which case a separate remote is the only solution.

Edit:
Actually, you can git pull [email protected]:me/foobar, which removes the caveat.
The choice is yours as to which is easier to remember.

Solution 3 - Git

I used a fairly simple method using the GitHub Web UI to do that:

  1. Open the original Git repository (not the forked Git repository me/foobar)
  2. Jump to the src folder, and open the file you want to change
  3. Click the pen icon. It will automatically create a label in your personal fork named "patch-1" based on the current version of the master repository: Enter image description here
  4. Enjoy! Enter image description here

Solution 4 - Git

The "Pull" app is an automatic set-up-and-forget solution. It will sync the default branch of your fork with the upstream repository.

Visit the URL, click the green "Install" button and select the repositories where you want to enable automatic synchronization.

The branch is updated once per hour directly on GitHub, on your local machine you need to pull the master branch to ensure that your local copy is in sync.

Also answered in https://stackoverflow.com/a/58965171/946850.

Solution 5 - Git

Recently (early May 2021) GitHub website provided a one-click button for exactly this purpose:

>

I can't resist the temptation to click it.

> After

See GitHub's official Tweet about this new feature.

Solution 6 - Git

Another option is to use the Update from upstreamRepoName/master button in GitHub for Mac (and I assume GitHub for Windows).

Enter image description here

Solution 7 - Git

I don't know how it can be done without adding another remote, however I always add the repo I forked from as the upstream remote so I could simply do:

git branch -a|grep remotes/upstream| while IFS="/" read p r b; do echo Syncing $r/$b to origin/$b; git push origin $r/$b:refs/heads/$b; done

This will sync all branches incl. creating new ones (remove the refs/heads/ to only update existing branches). If any of your branches has diverged it will throw an error for that branch.

Solution 8 - Git

I would simply use:

git pull [email protected]:someone/foobar <branch_name> && git push

Solution 9 - Git

  1. Visit https://github.com/me/foobar/compare/master...someone:master (of course replacing me, someone and foobar with corresponding repo and user names)

  2. If you see green text Able to merge then press Create pull request

  3. On the next page, scroll to the bottom of the page and click Merge pull request and Confirm merge.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Question1aceView Question on Stackoverflow
Solution 1 - GitOlufemi Israel OlanipekunView Answer on Stackoverflow
Solution 2 - Git1aceView Answer on Stackoverflow
Solution 3 - GitNadirView Answer on Stackoverflow
Solution 4 - GitkrlmlrView Answer on Stackoverflow
Solution 5 - GitiBugView Answer on Stackoverflow
Solution 6 - GitSteve MoserView Answer on Stackoverflow
Solution 7 - GitThomas Guyot-SionnestView Answer on Stackoverflow
Solution 8 - Gitcybergeek654View Answer on Stackoverflow
Solution 9 - GitIlyichView Answer on Stackoverflow