Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

OS 5.2 (2 of 3): Version control, conflicts and reviews

The whole lesson, free. Read it and have a go at the activities. To work the tasks and labs in the real lesson, press Start lab, with no account needed.

60 minutes

A quick check that you are not a bot, then your own lab opens on the interactive lesson.

Already have an account? Sign in

final_FINAL_v3_really.docx

Have you ever saved a file as "essay_final", then "essay_final2", then "essay_final_really"?

Now imagine five people do this to the same program. Nobody knows which copy is the real one.

Teams solve this with version control. Version control means a tool that records every change to your files. Today you use it with a partner. You will also make a mistake on purpose, and fix it.

Key words

WordWhat it meansExample
Version controlA tool that records every change, so you can go back.
Source controlVersion control for a team's code, with rules on who changes what.
RepositoryA store for a project and its full history.
CommitA saved step in the history, with a message.
CloneMake your own copy of a repository.
StageChoose which changes go into the next commit.git add team.txt
PushSend your commits to the shared repository.
PullBring other people's commits into your copy.
Merge conflictTwo changes to one line that Git cannot join.
Pull requestA request to merge a branch after a review.

The cells students fill in are left blank in this preview.

Version control or source control?

The two words are close. Version control records the history of any files and lets you go back.

Source control is about source code in a team. It adds sharing, branches, reviews and rules about who may change what.

Git is the tool. A server such as Gitea, GitHub or GitLab holds the shared copy.

Check: Git words

Have a go

Check: Git words

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Two people change one file

Press Start the lab and wait until it is running. The terminal has Git. The server is Gitea, at http://gitea:3000. Sign in at the Gitea tab as student with the password student.

You will play two people, Alice and Bob. Each gets a folder. Both change the same file. That makes the conflict.

1. Your name for Git

Command
git config --global user.name "Student"

A command for the lesson’s lab terminal. It is shown here and not run.

2. Your email for Git

Command
git config --global user.email "[email protected]"

A command for the lesson’s lab terminal. It is shown here and not run.

3. Alice gets a copy

Command
git clone http://student:student@gitea:3000/student/hello-git.git ~/alice

A command for the lesson’s lab terminal. It is shown here and not run.

4. Bob gets a copy

Command
git clone http://student:student@gitea:3000/student/hello-git.git ~/bob

A command for the lesson’s lab terminal. It is shown here and not run.

5. Be Alice

Command
cd ~/alice

A command for the lesson’s lab terminal. It is shown here and not run.

6. Alice makes a file

Command
echo "Version: Alice" > team.txt

A command for the lesson’s lab terminal. It is shown here and not run.

7. Alice stages it

Command
git add team.txt

A command for the lesson’s lab terminal. It is shown here and not run.

8. Alice commits

Command
git commit -m "Alice adds team.txt"

A command for the lesson’s lab terminal. It is shown here and not run.

9. Alice pushes first

Command
git push

A command for the lesson’s lab terminal. It is shown here and not run.

10. Now be Bob

Command
cd ~/bob

A command for the lesson’s lab terminal. It is shown here and not run.

11. Bob makes the same file

Command
echo "Version: Bob" > team.txt

A command for the lesson’s lab terminal. It is shown here and not run.

12. Bob stages it

Command
git add team.txt

A command for the lesson’s lab terminal. It is shown here and not run.

13. Bob commits

Command
git commit -m "Bob adds team.txt"

A command for the lesson’s lab terminal. It is shown here and not run.

14. Bob tries to push

Command
git push

A command for the lesson’s lab terminal. It is shown here and not run.

Git said no

Note

Bob's push is rejected. The server has a commit Bob does not have: Alice's. Git will not let Bob overwrite it. Bob must pull first.

15. Bob pulls

Command
git pull --no-rebase

A command for the lesson’s lab terminal. It is shown here and not run.

16. Look at the file

Command
cat team.txt

A command for the lesson’s lab terminal. It is shown here and not run.

Reading the conflict

Git put both versions in the file. The line <<<<<<< HEAD starts Bob's version. The line ======= splits them. The line >>>>>>> ends Alice's version.

Git cannot know which is right. You decide. Here, the team wants both names on one line.

Check: read the conflict

Have a go

Check: read the conflict

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

17. Write the fixed file

Command
echo "Version: Alice and Bob" > team.txt

A command for the lesson’s lab terminal. It is shown here and not run.

18. Mark it fixed

Command
git add team.txt

A command for the lesson’s lab terminal. It is shown here and not run.

19. Finish the merge

Command
git commit -m "Fix the conflict"

A command for the lesson’s lab terminal. It is shown here and not run.

20. Push at last

Command
git push

A command for the lesson’s lab terminal. It is shown here and not run.

Open a pull request and review it

Now work as a team on a branch. In the terminal, run these commands one by one. First git checkout -b bob-note. Then echo "A note from Bob" > note.txt. Then git add note.txt. Then git commit -m "Add a note". Last, git push -u origin bob-note. Open the Gitea tab and open student/hello-git. Press New Pull Request for bob-note and create it. Show it to your partner on your screen. Your partner reviews it and tells you one comment. Write that comment on a line in the Files Changed tab, then press Merge. Write four lines. Say what the conflict looked like. Say how you fixed it. Say what a pull request is for. Say what you would use a branch for in a real team.

A teacher marks this in a college. Nothing you write here is kept: it goes when you leave the page.

Make a free account to save your work, or press Start lab to work through the whole lesson.

Exit quiz

Have a go

Exit quiz

5 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Teach this lesson with your class

On a college account your students work the tasks and the labs as well, and every mark is kept for you.