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
| Word | What it means | Example |
|---|---|---|
| Version control | A tool that records every change, so you can go back. | |
| Source control | Version control for a team's code, with rules on who changes what. | |
| Repository | A store for a project and its full history. | |
| Commit | A saved step in the history, with a message. | |
| Clone | Make your own copy of a repository. | |
| Stage | Choose which changes go into the next commit. | git add team.txt |
| Push | Send your commits to the shared repository. | |
| Pull | Bring other people's commits into your copy. | |
| Merge conflict | Two changes to one line that Git cannot join. | |
| Pull request | A 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 questionsTwo 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
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
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
git clone http://student:student@gitea:3000/student/hello-git.git ~/aliceA command for the lesson’s lab terminal. It is shown here and not run.
4. Bob gets a copy
git clone http://student:student@gitea:3000/student/hello-git.git ~/bobA command for the lesson’s lab terminal. It is shown here and not run.
5. Be Alice
cd ~/aliceA command for the lesson’s lab terminal. It is shown here and not run.
6. Alice makes a file
echo "Version: Alice" > team.txtA command for the lesson’s lab terminal. It is shown here and not run.
7. Alice stages it
git add team.txtA command for the lesson’s lab terminal. It is shown here and not run.
8. Alice commits
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
git pushA command for the lesson’s lab terminal. It is shown here and not run.
10. Now be Bob
cd ~/bobA command for the lesson’s lab terminal. It is shown here and not run.
11. Bob makes the same file
echo "Version: Bob" > team.txtA command for the lesson’s lab terminal. It is shown here and not run.
12. Bob stages it
git add team.txtA command for the lesson’s lab terminal. It is shown here and not run.
13. Bob commits
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
git pushA 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
git pull --no-rebaseA command for the lesson’s lab terminal. It is shown here and not run.
16. Look at the file
cat team.txtA 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 questions17. Write the fixed file
echo "Version: Alice and Bob" > team.txtA command for the lesson’s lab terminal. It is shown here and not run.
18. Mark it fixed
git add team.txtA command for the lesson’s lab terminal. It is shown here and not run.
19. Finish the merge
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
git pushA 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