World map

 

BM: Baca dalam Bahasa Melayu

World 4: Hello GitHub

Forks and syncing

You will learn: how to copy someone's project into your account and keep your copy up to date.

The problem

Mei’s recipe site has a typo. You can’t push to her repo. How can you help?

Pick one answer.

Watch

Tap each point on the timeline.

A fork: Your own copy of someone else's project, in your account. is your own copy of someone’s repo, on GitHub. Tap each step.

Watch

After adding upstream, git remote -v lists two remotes: origin is your fork, upstream is Mei's repo. Terminal output: $ git remote add upstream https://github.com/mei/recipes.git $ git remote -v origin https://github.com/you/recipes.git (fetch) origin https://github.com/you/recipes.git (push) upstream https://github.com/mei/recipes.git (fetch) upstream https://github.com/mei/recipes.git (push)

Your clone knows origin: your fork. Add Mei’s repo as a second remote. The usual name for it is upstream: The remote branch your branch follows, like origin/main. For a fork, also the usual name for the original repo..

Predict

Mei adds a roti canai recipe to her repo. Does your fork get it by itself?

Pick one answer.

Try it

Sync your fork: add upstream, fetch, merge, then push.

62de120b17f517

Check

GitHub also gives your fork a Sync fork button. On your laptop, it’s these steps. Put them in order.

First step at the top. Put these in order. Use the arrows, or drag.

  • git push
  • git remote add upstream <Mei’s address>
  • git fetch upstream
  • git merge upstream/main

Check

Fork habits: good, or needs work? Swipe each one.

Swipe right for good, left for needs work. Or use the buttons.

1 / 3

Sync your fork before you start new work

Sync your fork before you start new work

You did it!

You can now fork a project and keep your copy in sync.

Go deeper (optional)

The GitHub CLI can do this too. gh repo fork --clone forks and clones in one go. gh repo sync updates a fork from its parent. A fork remembers the original, so pull requests know where to go.