Course outline · 0% complete

0/28 lessons0%

Course overview →

push and pull

lesson 7-2 · ~10 min · 19/28

your computerlocal repositoryGitHuborigingit pushgit pull
push uploads your new commits to the remote, pull downloads new commits from it and merges them into your branch.

Sending commits up: git push

Your commits are born local. Nobody on GitHub sees them until you push:

$ git push origin main
To https://github.com/octocat/recipe-book.git
   a1b2c3d..c7d8e9f  main -> main

Read it as "send my new main commits to origin." The very first push of a new branch adds -u:

$ git push -u origin main

-u links your local branch to the remote one, so from then on plain git push and git pull know where to go without you naming them.

Push only uploads commits. Uncommitted edits and staged-but-uncommitted changes stay home, which is one more reason the commit rhythm from lesson 2-3 matters.

Getting commits down: git pull

While you slept, a teammate pushed commits. Your clone doesn't update itself, you ask for the news:

$ git pull
Updating c7d8e9f..f0e9d8c
Fast-forward
 cake.txt | 2 +-

git pull downloads the remote's new commits and merges them into your current branch, often as a fast-forward from lesson 5-3.

The rite of passage every beginner hits: your push gets rejected.

$ git push origin main
 ! [rejected]        main -> main (fetch first)
error: failed to push some refs

Translation: the remote has commits you don't have, and Git won't let you push past them blindly. The fix is the polite order: pull first (merging their work into yours, possibly meeting a unit-6 conflict), then push. Pull before you start working and before you push, and rejections become rare.

Live the rejected-push rite of passage. You committed locally, but a teammate pushed to origin while you worked.

Step 1/3: Try to push your main branch to origin.

~/recipe-book $ 

Quiz

Your push was rejected with "fetch first" because a teammate pushed while you were working. What's the correct next move?

Problem

git pull is really two Git operations performed back to back. Name them, in order, like "X and Y".