Git without fear · Chapter 20 of 28
Remotes and your first push
By the end of this chapter you can point your repository at GitHub, push a branch there, and tell at a glance whether GitHub has your latest commits. Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.
- Part: Teamwork
- 4 tasks
- Git
- In the all labs plan
The first 2 chapters of Git without fear are free. This one comes with the all labs plan.
Why you need this
Everything you have made so far lives on your laptop. If the laptop dies, Tapri's menu, price list and order counter die with it, and nobody else can see or build on them. Kabir has made Tapri's repository on GitHub, empty and waiting, and wants your three commits in it before lunch.
Bunty "helpfully" connected GitHub already, and typed the address wrong. Your commits are not going anywhere, and nothing you have learned so far talks to another copy of the repository: git commit and git log only ever see this folder.
What you build: 4 tasks
Each task has tests. You write the code in the lab's editor and press Check.
- Task 1
Fix origin's address
Bunty added origin with a typo in its address. Fix the address.
1. List the remotes with their addresses, as in the lesson. Read origin's address letter by letter.
2. Change origin's address in place. Do not add origin again: the name is already taken.
3. The right address is /home/student/.lab/remotes/20-remotes-and-push/tapri.git
4. List the remotes again. Both lines for origin must end in tapri.git.
To pass: origin points at that address, for fetching and for pushing. Keep the name origin.
- Task 2
Push main to GitHub
Send your main to GitHub. GitHub's repository is empty now.
1. Fix origin's address first (task 1).
2. Push main to origin with git push.
3. Add the -u option to this push. It also does task 3.
To pass: GitHub's main has exactly the same commits as your main, all three of them, up to Count the orders.
- Task 3
Make main track GitHub's main
Make your main remember GitHub's main. This is called its upstream.
1. Push main with the -u option once. It sets the upstream.
2. Run git status. It says your branch is up to date with 'origin/main'.
To pass: the upstream of your main is origin/main.
- Task 4 · interview question
Interview: where does this repository push to?
Interview question: which command lists every remote, with the addresses it fetches from and pushes to?
1. Find the command in the lesson. You used it in task 1.
2. Write it into answer.txt, exactly as you type it, starting with git.
3. echo with > writes text into a file. Put the command in quotes.
To pass: answer.txt has that command at the start of the file, beginning with git.
What you will learn
- A remote: a short name, like origin, for the address of another copy of the repository.
- git remote -v and git remote set-url: see where a remote points, and fix a wrong address in place.
- git push -u: send a branch to GitHub, and remember where it goes.
- origin/main: your laptop's record of where GitHub's main is.
More in Teamwork
Build "Remotes and your first push" yourself
Your first week on Tapri’s team, and every Git situation it throws at you. A real editor and terminal in your browser, AI that explains, and a Check that says when it works.
The first 2 chapters of Git without fear are free. This one comes with the all labs plan.