Git basics

Update your fork from the original repo

Pull the latest changes from the original project into your fork, so your copy doesn't fall behind.

Fill these in once
  1. Check your fork knows the original
    Terminal
    git remote -v

    Look for a line starting with upstream. If it's missing, run the next step. If it's there, skip it.

  2. Add the original as upstream
    Terminal
    git remote add upstream https://github.com/octocat/hello-world.git
  3. Download the original's latest changes
    Terminal
    git fetch upstream
  4. Switch to your main branch
    Terminal
    git switch main
  5. Bring those changes into your branch
    Terminal
    git merge upstream/main

    If you haven't changed main yourself, this just moves it forward with no merge commit.

  6. Send the updated branch to your fork on GitHub
    Terminal
    git push origin main
  7. Or do it all in one go with GitHub CLI
    Terminal
    gh repo sync your-name/hello-world

    Optional. Updates the fork on GitHub only. Run git pull afterwards to update your computer too.

Check it worked

  1. Check your branch matches the original
    Terminal
    git log --oneline -3 upstream/main main
Undo it
  1. Undo the merge before you push
    Terminal
    git reset --hard ORIG_HEAD

    Puts your branch back where it was. Careful: it also throws away changes you haven't committed.

  1. Check your fork knows the original
    Terminal · Ubuntu / Debian
    git remote -v

    Look for a line starting with upstream. If it's missing, run the next step. If it's there, skip it.

  2. Add the original as upstream
    Terminal · Ubuntu / Debian
    git remote add upstream https://github.com/octocat/hello-world.git
  3. Download the original's latest changes
    Terminal · Ubuntu / Debian
    git fetch upstream
  4. Switch to your main branch
    Terminal · Ubuntu / Debian
    git switch main
  5. Bring those changes into your branch
    Terminal · Ubuntu / Debian
    git merge upstream/main

    If you haven't changed main yourself, this just moves it forward with no merge commit.

  6. Send the updated branch to your fork on GitHub
    Terminal · Ubuntu / Debian
    git push origin main
  7. Or do it all in one go with GitHub CLI
    Terminal · Ubuntu / Debian
    gh repo sync your-name/hello-world

    Optional. Updates the fork on GitHub only. Run git pull afterwards to update your computer too.

Check it worked

  1. Check your branch matches the original
    Terminal · Ubuntu / Debian
    git log --oneline -3 upstream/main main
Undo it
  1. Undo the merge before you push
    Terminal · Ubuntu / Debian
    git reset --hard ORIG_HEAD

    Puts your branch back where it was. Careful: it also throws away changes you haven't committed.

  1. Check your fork knows the original
    PowerShell
    git remote -v

    Look for a line starting with upstream. If it's missing, run the next step. If it's there, skip it.

  2. Add the original as upstream
    PowerShell
    git remote add upstream https://github.com/octocat/hello-world.git
  3. Download the original's latest changes
    PowerShell
    git fetch upstream
  4. Switch to your main branch
    PowerShell
    git switch main
  5. Bring those changes into your branch
    PowerShell
    git merge upstream/main

    If you haven't changed main yourself, this just moves it forward with no merge commit.

  6. Send the updated branch to your fork on GitHub
    PowerShell
    git push origin main
  7. Or do it all in one go with GitHub CLI
    PowerShell
    gh repo sync your-name/hello-world

    Optional. Updates the fork on GitHub only. Run git pull afterwards to update your computer too.

Check it worked

  1. Check your branch matches the original
    PowerShell
    git log --oneline -3 upstream/main main
Undo it
  1. Undo the merge before you push
    PowerShell
    git reset --hard ORIG_HEAD

    Puts your branch back where it was. Careful: it also throws away changes you haven't committed.

New to Fork? I explain it in plain English on Layman Terms.