Module 2 · Git: the 20 everyday commands · Lesson 11 of 16

Share work: clone, push, pull, fetch

Copy a project from GitHub, send your commits up, and bring your teammates' work down.

In this lesson · about 22 minutes

  • Copy a remote repository with git clone
  • Upload commits with git push (and git push -u the first time)
  • Tell git fetch (look) apart from git pull (look and update)
  • Recover when a push is rejected because a teammate pushed first

Key terms

Say the meaning to yourself, then tap a card to check.

Why "Your branch is up to date" can be wrong

Git does not watch the internet. git status compares your branch with origin/main, which is only what you last heard from the remote. If a teammate pushed ten minutes ago, status still says "up to date" until you git fetch.

Rejected pushes

If someone pushed before you, your push is rejected ("fetch first"). Nothing is lost. Run git pull to bring their work in (Git combines it with yours), then git push again.

Starting from scratch

For a brand-new project, connect it once with git remote add origin URL, then git push -u origin main. The -u remembers the link, so afterwards plain git push and git pull are enough.

Practice terminal · missions

Clone the family recipe book and add a recipe

Mia keeps a shared recipe book at https://github.example/noviq/recipes.git.

Missions 0 of 6

  1. 1Clone https://github.example/noviq/recipes.git
  2. 2Go into the new folder and list the files.
  3. 3Show the history, one line each.
  4. 4Write a new recipe file: echo "# Doro wat" > doro.md
  5. 5Stage and commit it with a good message.
  6. 6Send your commit to the shared copy.
sam@practice-box:~

Type a command and press Enter. Try help to list commands. Tab finishes names, ↑ repeats.

No Git repository here yet.

You are in ~. Git pictures appear once you cd into a project that is a repository, or run git init or git clone.

  • ~ (/home/sam)you are here
  • documents
  • notes.txt
  • website
  • index.html
  • README.md
  • style.css

Practice terminal · missions

Mia has been busy: fetch, pull, push

Sam's website repository is already set up. Overnight, Mia pushed two commits and a new branch. Extra: the ☁ A teammate pushes button makes Mia push again whenever you like.

Missions 0 of 6

  1. 1Check the status.
  2. 2Download the news from origin without changing your files.
  3. 3Check the status again.
  4. 4Bring Mia's commits into your branch and files.
  5. 5Add a line to README.md and commit it in one go: echo "Closed on holidays" >> README.md && git commit -am "Note holiday closing"
  6. 6Push your commit.
sam@practice-box:~/website

Type a command and press Enter. Try help to list commands. Tab finishes names, ↑ repeats.

Repository ~/website · on main

1 · Working folder

The files you edit

  • README.mdsaved
  • index.htmlsaved
  • style.csssaved

2 · Staging area

Packed for the next commit

  • (nothing staged: use git add)

3 · Commit history (this computer)

Each dot is a saved snapshot. Labels are branches, tags and what you last heard from origin.

b644ba3HEAD → mainorigin/mainAdd phone number to footer
534d516Add styles
dd28f37Add home page

☁ Remote: origin

https://github.example/sam/website.git

  • mainb77dd66Mention pastries on the home pagehas new work
  • dark-mode913ef77Try a dark colour themenot on your computer

Check your understanding0 of 4 correct

Question 1

1.What is the difference between git fetch and git pull?

Question 2

2.Your push is rejected with 'fetch first'. What do you do?

Question 3

3.What does -u do in git push -u origin main?

Question 4

4.You want your own copy of an existing project from GitHub, with its history. Which command?

Quiz score: 0 of 4

Tip: answer every quiz question correctly first.

Written by Noviq Academy in its own words. The practice terminal is a simulation that runs in your browser: it imitates Linux (Ubuntu-style output) and Git closely, but it is not a real computer, and real output can differ slightly. The servers, people, web addresses and GitHub addresses in the labs are made up. Linux is a trademark of Linus Torvalds; Git and GitHub belong to their owners. Read-aloud uses your device's built-in voices.