Track a first change
- Lesson 3
- 30 min
- Module 1: Understand a repository
Lesson 3 of 15 · Git and Team Development EssentialsTrack a first change
1. Understand a repository
2. Work with branches and remotes
3. Collaborate through reviews
4. Resolve and recover
5. Release and hotfix practice
What you will be able to do
Save your work as small, named steps, and see exactly what changed in each step. This is the main thing that you do with Git every day.
Before you startWhat to know and to have ready
What you need to know
- What a repository is, from Set up Git: A repository is a folder with a history.
- What
git statusshows, from Set up Git: Step 3: make a repository.
What you need on your computer
-
Git, with your name and email address. You set them in Set up Git: Step 2: tell Git who you are. To check them, run
git config --global --list. -
The empty repository
~/projects/ticket-notes. You made it in Set up Git: Step 3: make a repository. In it,git statusshowsNo commits yet. If the folder is missing, do that step again. -
If the repository is missing or broken, a script can make the start state of this lesson again. In
~/projects, run:Terminal window git clone https://github.com/Nextia-Intelligence/nextia-learning-labs.gitsh nextia-learning-labs/C14/setup.sh m01-l03 --resetRun the
git clonecommand only once. If you already have thenextia-learning-labsfolder, rungit -C nextia-learning-labs pullinstead. Pull-request sequence: Set up the practice lab explains the script in full. The script makes~/projects/c14-lab/ticket-notes: an empty repository onmain, with no commits and no remote. Then use~/projects/c14-labin place of~/projectsin this lesson.--resetdeletes an olderc14-labfolder first, but your~/projects/ticket-notesdoes not change. -
A text editor, for example Visual Studio Code. Any editor that saves plain text works. To open a terminal in your editor, see Terminal bridge: Open a terminal from your editor.
Three places for your changes
Section titled “Three places for your changes”Git does not save every edit automatically. You choose what to save, and when. To do this, Git keeps your changes in three places:
- The working tree is the files in your project folder, as you see them in your editor. When you edit a file, you change the working tree.
- The staging area is a list of the changes that go into your next save. You put a change there with
git add. - The commit history is the list of saved steps. You save the staging area as a new step with
git commit.
A commit is one saved step. It is a snapshot of the project, with a message that says why you made the change. Git also records the author, the date, and an ID for the commit.
Why have a staging area? It lets you choose. You can edit five files, then save two of them as one commit and three as another. Each commit then contains one clear change, which is easier to review and to undo.
Worked example: Amira’s first commit
Section titled “Worked example: Amira’s first commit”Amira is in ~/projects/ticket-notes. She makes a file called README.md in her editor, with this text:
# Ticket notes
Notes about support tickets.She saves the file, and asks Git for the state of the repository:
git statusOn branch main
No commits yet
Untracked files: (use "git add <file>..." to include in what will be committed) README.md
nothing added to commit but untracked files present (use "git add" to track)README.md is untracked: it is in the working tree, but Git does not track it yet. She adds it to the staging area, and checks again:
git add README.mdgit statusOn branch main
No commits yet
Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: README.mdThe file is now under “Changes to be committed”. This is the staging area. Next, she saves it as a commit. The -m option gives the message:
git commit -m "Add README"[main (root-commit) 763ec59] Add README 1 file changed, 3 insertions(+) create mode 100644 README.mdThe output shows the branch (main), a short ID (763ec59) and the message. root-commit means that this is the first commit in the repository. To see the history, she runs git log:
git logcommit 763ec59e42a90d5d11f064bc677d31b91bfc4e39 (HEAD -> main)Author: Amira Khan <amira@example.com>Date: Mon Oct 5 20:31:22 2026 -0400
Add READMEThe long text after commit is the commit hash: an ID that Git calculates from the contents of the commit. No two commits have the same hash. Git usually shows only the first seven characters, for example 763ec59. Your hash is different, because your commit has a different author and time.
Worked example: see a change before you save it
Section titled “Worked example: see a change before you save it”Amira changes the last line of README.md to Notes about support tickets for the help desk. She also makes a new file, tickets.txt:
Ticket 101: printer offline. Restarted the spooler.Now she has two changes. To see a short summary, she uses git status --short:
git status --short M README.md?? tickets.txtTo see the exact change in README.md, she uses git diff. A diff shows the lines that changed:
git diffdiff --git a/README.md b/README.mdindex 8f872d3..a30ec45 100644--- a/README.md+++ b/README.md@@ -1,3 +1,3 @@ # Ticket notes
-Notes about support tickets.+Notes about support tickets for the help desk.Read a diff like this:
- A line that starts with
-was removed. A line that starts with+was added. A changed line shows as one of each. - Lines with no sign did not change. Git shows them so that you can see where the change is.
@@ -1,3 +1,3 @@gives the line numbers: lines 1 to 3 in the old file, and lines 1 to 3 in the new file.
git diff does not show tickets.txt, because Git does not track that file yet. git diff only compares tracked files.
Amira wants two commits: one for the README change and one for the ticket. She stages only the README:
git add README.mdgit status --shortM README.md?? tickets.txtThe M moved from the second column to the first column. The two columns are the most useful part of git status --short:
| Code | First column: staging area | Second column: working tree |
|---|---|---|
M |
The change is staged. It goes into the next commit. | No other changes. |
M |
Nothing is staged. | The file changed, and the change is not staged. |
MM |
A change is staged. | The file changed again after you staged it. |
?? |
The file is untracked. | The file is untracked. |
A |
A new file is staged. | No other changes. |
git diff shows unstaged changes only. Now that the README change is staged, she uses git diff --staged to see what the next commit will contain. The output is the same diff as before. Then she makes two commits:
git commit -m "Describe who the notes are for"git add tickets.txtgit commit -m "Add first ticket note"git log --onelined8ae027 (HEAD -> main) Add first ticket note49397ba Describe who the notes are for763ec59 Add READMEgit log --oneline shows one commit on each line, newest first. (HEAD -> main) marks the commit that you are on now. You learn what this means in the next module.
Guided practice: make your first commits
Section titled “Guided practice: make your first commits”Do the worked example in your own ticket-notes repository. After each command, compare your output with Amira’s.
-
Check that you are in the repository:
Terminal window cd ~/projects/ticket-notesgit statusThe output shows
No commits yet. -
In your editor, make
README.mdwith the three lines from the first worked example. Save the file. -
Run
git status.README.mdis under “Untracked files”. -
Stage the file:
Terminal window git add README.md -
Run
git status.README.mdis under “Changes to be committed”. -
Commit it:
Terminal window git commit -m "Add README"The output starts with
[main (root-commit). -
Run
git log --oneline. The output shows one commit. -
Change the last line of
README.md, and maketickets.txtwith one ticket note. Save both files. -
Run
git status --short. The output showsM README.mdand?? tickets.txt. -
Run
git diff. The output shows one-line and one+line. -
Stage and commit the README change:
Terminal window git add README.mdgit commit -m "Describe who the notes are for" -
Stage and commit the ticket note:
Terminal window git add tickets.txtgit commit -m "Add first ticket note" -
Run
git log --oneline. The output shows three commits. Rungit status. The output saysnothing to commit, working tree clean.
Your turn: two commits, then inspect them
Section titled “Your turn: two commits, then inspect them”Make two more commits in ticket-notes, one for each change:
- Add a second ticket note to
tickets.txt. - Add a new file,
contacts.txt, with the name of a help desk team.
Then, for each of your two new commits, use git show --stat to see which files it changed. Get the short hashes from git log --oneline, and use yours instead of d8ae027:
git show --stat d8ae027 tickets.txt | 1 + 1 file changed, 1 insertion(+)Each of your commits must change only one file. If a commit changed both files, you staged both before you committed. You learn to undo a commit in Module 4. For now, make one more change to each file, and commit them separately.
Common mistake
Git opens a strange editor
Symptom: you run git commit without -m. The terminal fills with a text screen, and the keys do not act as you expect. The bottom line can show ~ characters, or the name of an editor such as Vim or nano.
Cause: Git needs a commit message. When you do not give one with -m, Git opens a text editor so that you can type it. The default editor on many systems is Vim, which works differently from other editors.
Fix: leave the editor without saving. Git then cancels the commit.
- In Vim: press Esc, type
:q!, then press Enter. - In nano: press Ctrl+X. If nano asks to save, press N.
Git shows Aborting commit due to empty commit message. Your staged changes stay staged. Run the commit again with -m "your message".
Common mistake
Nothing added to commit
Symptom: you run git commit -m "Add ticket", and Git shows nothing added to commit but untracked files present, or no changes added to commit.
Cause: the staging area is empty. You edited files, but you did not run git add, so Git has nothing to save.
Fix: run git status to see your changes. Run git add for each file that you want in the commit. Then commit again.
Check your understanding
Predict: Amira stages tickets.txt with git add. Then she adds one more line to tickets.txt and saves it. What does git status --short show? What goes into her next commit?
Show the answer
It shows MM tickets.txt. The first M is the staged change. The second M is the newer change in the working tree, which is not staged. The next commit contains only the staged version: the file as it was when she ran git add. To include the new line, she must run git add tickets.txt again.
Does your answer have the main points of ours?
Sign in and enroll in the course to save your answers. Every check counts toward the certificate.
Check your understanding
Practical check: for each file in this git status --short output, say if its change is unstaged, staged, or untracked: 'M README.md', ' M contacts.txt', '?? notes.txt'.
Show the answer
README.md: staged. TheMis in the first column. It goes into the next commit.contacts.txt: unstaged. TheMis in the second column. Git tracks the file, but this change is not in the staging area.notes.txt: untracked. Git does not track this file yet.
A change that is already committed does not appear in git status. You see it with git log and git show.
Does your answer have the main points of ours?
Sign in and enroll in the course to save your answers. Every check counts toward the certificate.
Recap
- Changes move from the working tree to the staging area with
git add, then into the commit history withgit commit. git statusandgit status --shortshow where each change is.git diffshows unstaged changes, andgit diff --stagedshows staged changes.- A commit hash identifies a commit.
git show <hash>shows what the commit really changed. - Stage only the changes that belong together, so each commit is one clear step.
This is the end of Module 1. In Module 2, you work on a separate line of changes with branches, and share your work with a remote.