Unit 8: Working Together
Two people, one project.
Unit 8 of 8 in Git and version control for kids. Its 4 lessons are When Push Is Refused, How Teams Really Work, Naming a Version and Git Master — below is everything each one explains, and a question or two from it to try.
Every terminal session on this page was replayed before it shipped, on a git whose every message is tested against the real one.
This unit opens with a fortnight’s trial of everything — no card needed — or with a family plan, bought in the iPhone app. The first two units of every track are free for ever. Try it in the app.
🚫 When Push Is Refused
Rejected
You both started from the same commit. Sam pushed first. Now your push is rejected.
Git is not being difficult. If it let you win, Sam’s commit would be wiped off the server. It is refusing to lose someone’s work.
Terminal
$ git push To https://github.com/team/site.git ! [rejected] main -> main (fetch first) error: failed to push some refs to 'https://github.com/team/site.git' hint: Updates were rejected because the remote contains work that you do not hint: have locally. This is usually caused by another repository pushing to hint: the same ref. If you want to integrate the remote changes, use hint: 'git pull' before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Pull, then push
The fix is always the same: pull first. Git merges their work with yours, then your push has somewhere to land.
Because you both changed different files, the merge is quiet.
Terminal
$ git pull From https://github.com/team/site 2c86b75..f6aa737 main -> origin/main Merge made by the 'ort' strategy. about.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 about.txt $ git push To https://github.com/team/site.git f6aa737..9e9515e main -> main $ git status On branch main Your branch is up to date with 'origin/main'. nothing to commit, working tree clean
Try it yourself
Why did git refuse the push?
- Your internet is broken
- The server has commits you do not have yet
- Your commit message was too short
- You are not allowed to push
Your push is rejected. What do you do?
- git pull, then git push again
- git push --force
- Delete the repo and clone it again
- Send the files by email
Answer them in the app
🌳 How Teams Really Work
Nobody works on main
On a real project, main is the version that works. People do not commit to it directly.
Instead: branch → commit → push the branch → someone reads it → merge into main. On GitHub, that "someone reads it" step is called a pull request.
Pushing a branch
Push a branch exactly like main — name it instead. Now your work is safely on the server and visible to everyone, without touching main at all.
Terminal
$ git push -u origin sound To https://github.com/team/game.git * [new branch] sound -> sound branch 'sound' set up to track 'origin/sound'. $ git branch -a main * sound remotes/origin/HEAD -> origin/main remotes/origin/main remotes/origin/sound
Try it yourself
What is a pull request?
- A git command
- A way to ask "please look at my branch, then merge it"
- Another word for git pull
- A message to the server
Why keep main working at all times?
- Git demands it
- So anyone can grab main and have something that works
- It makes commits smaller
- It stops conflicts happening
Answer them in the app
🏷️ Naming a Version
Tags
A hash like a1b2c3d is a terrible name for "the version we showed at the school fair".
git tag v1.0 sticks a permanent label on the current commit. Unlike a branch, a tag never moves.
Terminal
$ git tag v1.0 $ git tag v1.0 $ git log --oneline d01bc39 (HEAD -> main, tag: v1.0) Finish version 1
Try it yourself
What is the difference between a branch and a tag?
- A branch moves forward as you commit; a tag stays put
- Tags are only for text files
- Branches cannot be deleted
- There is no difference
Answer it in the app
🏆 Git Master
Try it yourself
Which of these can actually lose work that git cannot get back?
- git commit
- git reset --hard, on changes you never committed
- git branch
- git status
What is the single best habit in this whole course?
- Commit often, with messages that say what changed
- Only ever commit once a month
- Never use branches
- Always use --force
Answer them in the app