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

Preview

Git: read the history, then branch

This is the first page of the lesson. Read it and have a go at the activities. The rest is in the full lesson.

45 minutes

Who changed this, and why?

A line in a file is wrong. Who wrote it? When? Why?

In a team, many people change the same code. Without a record, nobody knows. With a tool called Git, every change has an author, a date and a message.

Key words

WordWhat it meansExample
Version controlA tool that records every change to your files, so you can go back.Git
StageChoose which changes go into the next commit.git add visitors.txt
RepositoryA folder of files with all its history.hello-git
CommitOne saved step in the history, with a message.Add a list of visitors
BranchA separate line of work. Your changes stay apart until you merge.add-my-name
MergeBring the changes of one branch into another.Merge add-my-name into main
HistoryThe list of all commits, newest first.git log
CloneMake your own copy of a repository.git clone
MainThe branch that holds the finished, shared code.main

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

Start the lab first

data-callouts.note.label

Press Start the lab on the bar at the top of this lesson. Wait until it says it is running. Each Run button types its command into your lab terminal, one after another. The option --no-pager makes Git show all the text at once. That is easier to read here.

1. Say who you are

Every commit has an author. Tell Git your name and your email. Run both commands.

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

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

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

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

2. Get a copy of the project

The lab has a project called hello-git. Clone it. Then go into its folder.

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

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

Command
cd hello-git

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

3. Read the history

Two people worked here before you. The first command lists the commits, newest first. The second shows, for each line of a file, who wrote it. The command is called blame, but it is not about blaming. It helps you find the right person to ask.

Command
git --no-pager log --oneline

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

Command
git --no-pager blame visitors.txt

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

Quick check: read the history

Have a go

Quick check: read the history

4 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

Your answers are marked here and are not kept. A college account keeps every student’s marks.

The lesson goes on

14 more parts of this lesson are in the full curriculum, with the tasks, the final check and the labs. A college account gives your students all of it.