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
| Word | What it means | Example |
|---|---|---|
| Version control | A tool that records every change to your files, so you can go back. | Git |
| Stage | Choose which changes go into the next commit. | git add visitors.txt |
| Repository | A folder of files with all its history. | hello-git |
| Commit | One saved step in the history, with a message. | Add a list of visitors |
| Branch | A separate line of work. Your changes stay apart until you merge. | add-my-name |
| Merge | Bring the changes of one branch into another. | Merge add-my-name into main |
| History | The list of all commits, newest first. | git log |
| Clone | Make your own copy of a repository. | git clone |
| Main | The 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.
git config --global user.name "Student"A command for the lesson’s lab terminal. It is shown here and not run.
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.
git clone http://student:student@gitea:3000/student/hello-git.gitA command for the lesson’s lab terminal. It is shown here and not run.
cd hello-gitA 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.
git --no-pager log --onelineA command for the lesson’s lab terminal. It is shown here and not run.
git --no-pager blame visitors.txtA 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 questionsYour answers are marked here and are not kept. A college account keeps every student’s marks.