Skip to content

Lesson 05 — Pushing and Pulling

Send committed work to GitHub and bring other people’s committed work from GitHub back to your computer.

The most important point in this lesson is simple: git push sends commits. It does not commit file changes for you.

Diagram distinguishing working files, staging, local commits, and GitHub. Commit creates local history; push sends committed work to GitHub; pull brings shared commits back.

PlaceWhat lives thereCommand that moves work
Working filesUnsaved or saved file editsSave in your editor
Staging areaThe next commit you are preparinggit add filename
Local Git historyCommits on your computergit commit -m "message"
GitHubCommits shared with othersgit push and git pull

Check yourself: If you only edited a file and did not commit, there is nothing for git push to send.

Terminal window
git push

Sends your local commits to GitHub.

Terminal window
git pull

Brings new commits from GitHub to your computer and updates your current branch.

Run:

Terminal window
git status

Useful status messages:

Message shapeMeaningCalm next step
working tree cleanNo uncommitted file changesPull or start work
Changes not staged for commitFile edits exist but are not stagedReview with git diff
Changes to be committedStaged edits are waitingReview with git diff --staged, then commit
Your branch is ahead of 'origin/main' by 1 commitYou have a local commit GitHub does not havePush
Your branch is behind 'origin/main'GitHub has commits you do not havePull

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

Terminal window
git pull

Expected shape when nothing new is available:

Already up to date.
  • I pulled the latest changes from GitHub.

Edit a file such as:

queries/01-count-visits.sql

For practice, add a comment that explains the query:

-- Count total visits in the starter data.

Save the file.

  • I made one small file change.
  • I saved the file.

Run:

Terminal window
git status
git diff

Git should show that a file changed, and git diff should show the exact lines.

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

Stage the file:

Terminal window
git add queries/01-count-visits.sql

Confirm what will be committed:

Terminal window
git status
git diff --staged

Commit the staged change:

Terminal window
git commit -m "docs: clarify visit count query"
  • 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 1 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

The -u connects your local branch to the branch on GitHub so future git push and git pull commands know where to go.

  • My commit was pushed to GitHub.

Open the repository in GitHub and check one of these:

  • the commit list,

  • the changed file,

  • or the branch page.

  • I opened the repository in GitHub.

  • I can see my change or commit.

Use this table when learners are unsure what has happened.

What you didHas Git saved a commit?Will git push send it?
Edited a file but did not save itNoNo
Saved a file but did not stage itNoNo
Staged a file but did not commitNoNo
Committed the staged changeYes, locallyYes
Pushed after committingYes, locally and on GitHubAlready sent

Before starting work each day:

Terminal window
git pull

Before and after each major step:

Terminal window
git status

Before staging:

Terminal window
git diff

Before committing:

Terminal window
git diff --staged
  • I can push commits to GitHub.
  • I can pull changes from GitHub.
  • I understand that push sends committed work up.
  • I understand that push does not commit file changes.
  • I understand that pull brings GitHub commits down.