Git basics

Push and pull your changes

Send your saved commits up to GitHub with push and bring everyone else's new work down with pull.

Fill these in once
  1. Pull the newest work first
    Terminal
    git pull

    Do this before you start and again before you push. It brings down anything other people added since you last looked.

  2. Push your commits
    Terminal
    git push

    Only commits are sent. Save your changes with a commit first.

  3. First push of a new branch
    Terminal
    git push -u origin main

    Only needed once per branch. After that, plain git push and git pull know where to go.

Check it worked

  1. Check you're in step with GitHub
    Terminal
    git status

    It should say your branch is up to date with origin.

Undo it
  1. Undo a pull that just went wrong
    Terminal
    git reset --hard ORIG_HEAD

    Only right after the pull. It also throws away changes you haven't committed.

  1. Pull the newest work first
    Terminal · Ubuntu / Debian
    git pull

    Do this before you start and again before you push. It brings down anything other people added since you last looked.

  2. Push your commits
    Terminal · Ubuntu / Debian
    git push

    Only commits are sent. Save your changes with a commit first.

  3. First push of a new branch
    Terminal · Ubuntu / Debian
    git push -u origin main

    Only needed once per branch. After that, plain git push and git pull know where to go.

Check it worked

  1. Check you're in step with GitHub
    Terminal · Ubuntu / Debian
    git status

    It should say your branch is up to date with origin.

Undo it
  1. Undo a pull that just went wrong
    Terminal · Ubuntu / Debian
    git reset --hard ORIG_HEAD

    Only right after the pull. It also throws away changes you haven't committed.

  1. Pull the newest work first
    PowerShell
    git pull

    Do this before you start and again before you push. It brings down anything other people added since you last looked.

  2. Push your commits
    PowerShell
    git push

    Only commits are sent. Save your changes with a commit first.

  3. First push of a new branch
    PowerShell
    git push -u origin main

    Only needed once per branch. After that, plain git push and git pull know where to go.

Check it worked

  1. Check you're in step with GitHub
    PowerShell
    git status

    It should say your branch is up to date with origin.

Undo it
  1. Undo a pull that just went wrong
    PowerShell
    git reset --hard ORIG_HEAD

    Only right after the pull. It also throws away changes you haven't committed.

New to Push and pull? I explain it in plain English on Layman Terms.