Skip to content

Lesson 05 — Pushing and Pulling

Send commits to GitHub and bring updates from GitHub back to your computer.

Terminal window
git push

Sends your local commits to GitHub.

Terminal window
git pull

Brings new commits from GitHub to your computer.

Before making your own change, get the latest work from GitHub:

Terminal window
git pull
  • I pulled the latest changes from GitHub.

Edit a file, such as README.md.

For practice, add one short sentence like:

Practicing push and pull.
  • I made one small file change.

Run:

Terminal window
git status

Git should show that a file has changed.

Important: a changed file is not ready to push yet. git push only sends commits to GitHub. It does not commit file changes for you.

  • I can see my changed file.
  • I understand that an uncommitted file change will not be pushed.

Stage the file:

Terminal window
git add README.md

Replace README.md with the file you changed.

Commit the staged change:

Terminal window
git commit -m "docs: practice pushing a commit"
  • I staged my changed file.
  • I committed the change.

Run:

Terminal window
git status

Git may say your branch is ahead of origin/main by one commit. That means you have a local commit that GitHub does not have yet.

  • I know whether I have local commits to push.

Run:

Terminal window
git push

If this is the first push on a new branch, Git may ask you to use:

Terminal window
git push -u origin branch-name
  • My commit was pushed to GitHub.
  • I opened the repository in GitHub.
  • I can see my change or commit.

Before starting work each day, run:

Terminal window
git pull

Before and after each major step, run:

Terminal window
git status
  • I can push commits to GitHub.
  • I can pull changes from GitHub.
  • I understand that push sends changes up.
  • I understand that pull brings changes down.