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

Preview

Git: when two people change one line

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

Two people, one line

Ana and Ben work on the same file. Both add a name at the end of the same list.

Ana finishes first. Then Ben tries to join his work to hers. Whose line should win?

Git does not guess. It stops and asks a person. Today you are that person.

Key words

WordWhat it meansExample
ConflictTwo changes to the same place that Git cannot join by itself.Two names on the same line
MergeBring the changes of one branch into another.git merge ben
BranchA separate line of work.ben
CommitOne saved step in the history.Add Ben
Merge commitA commit that joins two lines of work.Merge branch ben
Conflict markersLines Git writes in the file to show both versions.<<<<<<< and >>>>>>>
ResolveChoose what the file should say, and save it.Keep both names
RepositoryA folder of files with all its history.hello-git
StageChoose which changes go into the next commit.git add visitors.txt
CloneMake your own copy of a repository.git clone ... team

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. You work in a new folder, so this lesson does not need the earlier one.

1. A fresh copy

First tell Git your name and email. Then clone the project (make your own copy) into a new folder called team. Then go into the folder.

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.

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

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

Command
cd team

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

2. Ben works on a branch

You play both people. First you are Ben. Make a branch, add a line, and commit. The -a in commit -am means: stage all changes to files that Git already knows. The -m gives the message.

Command
git switch -c ben

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

Command
echo "Ben" >> visitors.txt

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

Command
git commit -am "Add Ben to the visitors list"

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

The lesson goes on

16 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.