Yet another git dedicated site
The LLM is experimental.
Model:
The AI helper runs on your own computer. The model downloads once (Smart ~2.3 GB, Fast ~1 GB).
🐢 Smart (4B) seems slow on this computer.
How Git works in one picture — then learn it step by step.✔ Every terminal on this page is real Git output.
- and beyond
💡 Simply put:
Why Git, how this course works, setup
What Git is — in two minutes
Git remembers every saved version of a folder, so you can see what changed, go back, and work with others without overwriting each other.
In one sentenceGit is a time machine for a folder: every commit is a snapshot you can return to.
📁 Repository
Your project folder plus its history, kept in a hidden .git folder.
📸 Commit
A saved snapshot with a message, an author and an id like 494f845.
🌿 Branch
A movable label on a line of commits. main is the usual default.
☁️ Remote
A shared copy on a server. Its usual nickname is origin.
🎒 Staging area
The changes that go into the next commit — you choose them with git add.
📍 HEAD
“You are here”: normally the branch you are on.
Check yourself: What does a commit save?
A commit is a snapshot of what you staged, stored in your local repository. Nothing goes to a server until you push.
How this course works
Six stages, from “alone on my laptop” to “in a team with a server”. Each stage ends with a small milestone.
Install Git and tell it who you are
Install once, check the version, then set the name and e-mail that go on every commit.
In one sentenceGit must know your name and e-mail before your first commit.
Download Git for Windows from git-scm.com, install with the default options, open Git Bash.
Open Terminal, type git --version. If Git is missing, macOS offers the Command Line Tools — accept.
sudo apt install git (Debian/Ubuntu) or sudo dnf install git (Fedora).
$ git --version
git version 2.43.0$ git config --global user.name "Alex Example"
$ git config --global user.email "alex@example.com"
$ git config --global init.defaultBranch main
$ git config --global --list
user.name=Alex Example
user.email=alex@example.com
init.defaultbranch=mainThe third line makes new repositories start on a branch called main.
Alone on your computer: commit, diff, history, undo
Create your first repository
Make a folder, put a file in it, and turn it into a repository with git init.
In one sentencegit init turns a normal folder into a repository.
$ mkdir -p ~/projects/first_commit
$ cd ~/projects/first_commit
$ pwd
/home/alex/projects/first_commit
$ printf '# First Commit\n\nA small Git practice repository.\n' > README.md
$ cat README.md
# First Commit
A small Git practice repository.
$ git init
Initialized empty Git repository in /home/alex/projects/first_commit/.git/
$ git status
On 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)Untracked means Git sees the file but is not keeping history for it yet.
Check yourself: Where does Git keep the history?
git init creates .git. Delete it and the history is gone (the files stay).
Your first commit
git add puts the file on the staging area; git commit saves the snapshot.
In one sentenceadd chooses, commit saves.
$ git add README.md
$ git status
On branch main
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: README.md
$ git commit -m "Add README"
[main (root-commit) bfb742d] Add README
1 file changed, 3 insertions(+)
create mode 100644 README.md
$ git log --oneline
bfb742d Add READMEroot-commit means this is the very first snapshot.
Check yourself: You changed a file but did not run git add. What does git commit save?
Only staged changes go into a commit. Use git add first.
The three areas: desk, tray, chest of drawers
Every file change lives in one of three places. Knowing where is the key to understanding Git.
In one sentenceChanges move from the working folder to the staging area to the local repository — and only then (stage 3) to a remote.
$ echo 'Learn the three areas.' >> README.md
$ echo '- buy milk' > todo.txt
$ git status
On branch main
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: README.md
Untracked files:
(use "git add <file>..." to include in what will be committed)
todo.txt
no changes added to commit (use "git add" and/or "git commit -a")
$ git status --short
M README.md
?? todo.txt
$ git add todo.txt
$ git status
On branch main
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: todo.txt
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: README.md
$ git status --short
M README.md
A todo.txt
$ git add README.md
$ git status
On branch main
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: README.md
new file: todo.txt
$ git status --short
M README.md
A todo.txt
$ git commit -m "Add todo list and a README line"
[main 494f845] Add todo list and a README line
2 files changed, 2 insertions(+)
create mode 100644 todo.txtIn --short the left column is the tray (staged), the right column is the desk.
📖 What do the two letters in git status --short mean?
Every line starts with two letters: XY 1st letter = the TRAY (staged) · 2nd letter = the DESK (changed, not staged yet). A dot “·” here means an empty place (a space). Files that are tracked and unchanged are not listed at all.
| letters | meaning | long git status shows it under |
|---|---|---|
| ?? | untracked A new paper with NO Git sticker. Git sees it but has never saved it — it is in no drawer until you git add it. | Untracked files |
| A· | added A new file, put on the tray. It goes into the next drawer. | Changes to be committed: new file |
| ·M | modified, not on the tray Changed on the desk only. The next drawer will NOT contain this change until you git add it. | Changes not staged for commit: modified |
| M· | modified, on the tray Changed and put on the tray: ready for the next drawer. | Changes to be committed: modified |
| AM | added, then changed again New file on the tray, and after git add you wrote more on the desk. The tray still holds the OLDER copy. | in BOTH sections |
| MM | on the tray, then changed again One change is on the tray AND a newer change is only on the desk. git add again to put the newest on the tray. | in BOTH sections |
| ·D | deleted, not on the tray You deleted the file on the desk. | Changes not staged: deleted |
Tip: first run git status — it explains everything in words. Use git status --short once the letters feel easy.
Check yourself: git status --short shows “MM README.md”. What does it mean?
Left M = staged part, right M = newer edits not staged yet. git add again to stage them too.
See exactly what changed: diff
git diff shows edits on your desk; git diff --staged shows what is on the tray.
In one sentencediff answers “what exactly changed?”, line by line.
$ echo '- practise git diff' >> todo.txt
$ git diff
diff --git a/todo.txt b/todo.txt
index 4fffeb6..fe1861a 100644
--- a/todo.txt
+++ b/todo.txt
@@ -1 +1,2 @@
- buy milk
+- practise git diff
$ git add todo.txt
$ git diff
$ git diff --staged
diff --git a/todo.txt b/todo.txt
index 4fffeb6..fe1861a 100644
--- a/todo.txt
+++ b/todo.txt
@@ -1 +1,2 @@
- buy milk
+- practise git diff
$ git commit -m "Add a practice item"
[main 3e43845] Add a practice item
1 file changed, 1 insertion(+)After git add, plain git diff shows nothing — the change moved to the tray; --staged shows it. Each @@ … @@ block is a hunk.
Read the history: log and show
Every commit is kept. git log lists them, git show opens one.
In one sentencelog is the list of saves, show opens one of them.
$ git log --oneline
3e43845 Add a practice item
494f845 Add todo list and a README line
bfb742d Add README
$ git log -1
commit 3e43845def435d52e7300f5ed9d959c2f74a1888
Author: Alex Example <alex@example.com>
Date: Thu Oct 1 09:31:00 2026 +0000
Add a practice item
$ git show --stat HEAD~1
commit 494f8457b8a9c994df7109619cdaa1d63e841a64
Author: Alex Example <alex@example.com>
Date: Thu Oct 1 09:25:00 2026 +0000
Add todo list and a README line
README.md | 1 +
todo.txt | 1 +
2 files changed, 2 insertions(+)The long id after commit is the full commit id; the first 7 characters are enough everywhere.
Check yourself: You want one line per commit. Which command?
Add --graph --all to see branches too.
Keep secrets and junk out: .gitignore
List files Git must never track — passwords, logs, build output — and commit that list.
In one sentence.gitignore is the “never pack this” list.
$ printf '.env\n*.log\n' > .gitignore
$ echo 'PASSWORD=secret' > .env
$ echo debug > app.log
$ git status --short
?? .gitignore
$ git status --short --ignored
?? .gitignore
!! .env
!! app.log
$ git add .gitignore
$ git commit -m "Ignore local files"
[main 0e9daad] Ignore local files
1 file changed, 2 insertions(+)
create mode 100644 .gitignore.env and app.log vanish from git status; --ignored shows them marked !!.
Undo on your desk: restore and amend
Throw away scribbles, take a file off the tray, or fix the last commit before anyone saw it.
In one sentencerestore cleans the desk or the tray; amend rewrites the last commit.
$ echo 'oops' >> README.md
$ git status --short
M README.md
$ git restore README.md
$ git status --short$ echo draft > draft.txt
$ git add draft.txt
$ git status --short
A draft.txt
$ git restore --staged draft.txt
$ git status --short
?? draft.txt$ echo '- use git restore' >> todo.txt
$ git commit -am "Add restor tip"
[main 5a4b1de] Add restor tip
1 file changed, 1 insertion(+)
$ git commit --amend -m "Add restore tip"
[main 812f50f] Add restore tip
Date: Thu Oct 1 09:53:00 2026 +0000
1 file changed, 1 insertion(+)
$ git log --oneline -2
812f50f Add restore tip
0e9daad Ignore local filesOnly amend commits you have not pushed yet: amend creates a new commit id.
Milestone 1: your Git diary
Put stage 1 together on your own computer.
🏁 Your tasks
Still alone: branches, merges, your first conflict
Branches: try things safely
A branch is a label that moves forward with your commits. Make one for every change.
In one sentenceA branch lets you work on something without touching main.
$ git switch -c feature/notes
Switched to a new branch 'feature/notes'
$ printf '# Notes\n\n- a branch is a movable label\n' > notes.md
$ git add notes.md
$ git commit -m "Add notes"
[feature/notes e7cddb6] Add notes
1 file changed, 3 insertions(+)
create mode 100644 notes.md
$ git branch
* feature/notes
main
$ git log --oneline --graph --all -4
* e7cddb6 Add notes
* 812f50f Add restore tip
* 0e9daad Ignore local files
* 3e43845 Add a practice item-c = create. Branch names like feature/… or fix/… are a common convention.
Switch between branches
Switching changes your files to that branch’s version — watch notes.md appear and disappear.
In one sentenceswitch moves HEAD and updates your files.
$ ls
README.md
app.log
notes.md
todo.txt
$ git switch main
Switched to branch 'main'
$ ls
README.md
app.log
todo.txt
$ git switch feature/notes
Switched to branch 'feature/notes'
$ ls
README.md
app.log
notes.md
todo.txtNothing was lost: notes.md lives in the branch’s commit.
Bring it back: fast-forward merge
If main did not move since you branched, merging just moves the main label forward.
In one sentenceA fast-forward merge moves the label; no new commit is needed.
$ git switch main
Switched to branch 'main'
$ git merge feature/notes
Updating 812f50f..e7cddb6
Fast-forward
notes.md | 3 +++
1 file changed, 3 insertions(+)
create mode 100644 notes.md
$ git log --oneline --graph -3
* e7cddb6 Add notes
* 812f50f Add restore tip
* 0e9daad Ignore local files
$ git branch -d feature/notes
Deleted branch feature/notes (was e7cddb6).When both moved: the merge commit
If main got new commits too, Git joins both lines with a merge commit that has two parents.
In one sentenceA merge commit has two parents and joins two lines of work.
$ git switch -c feature/todo
Switched to a new branch 'feature/todo'
$ echo '- learn merging' >> todo.txt
$ git commit -am "Add merging to todo"
[feature/todo 996d5e3] Add merging to todo
1 file changed, 1 insertion(+)
$ git switch main
Switched to branch 'main'
$ echo 'Branches are cheap.' >> README.md
$ git commit -am "Add a README line on main"
[main 70be422] Add a README line on main
1 file changed, 1 insertion(+)
$ git log --oneline --graph --all -4
* 70be422 Add a README line on main
| * 996d5e3 Add merging to todo
|/
* e7cddb6 Add notes
* 812f50f Add restore tip
$ git merge --no-edit feature/todo
Merge made by the 'ort' strategy.
todo.txt | 1 +
1 file changed, 1 insertion(+)
$ git log --oneline --graph -5
* e6e6b44 Merge branch 'feature/todo'
|\
| * 996d5e3 Add merging to todo
* | 70be422 Add a README line on main
|/
* e7cddb6 Add notes
* 812f50f Add restore tip
$ git branch -d feature/todo
Deleted branch feature/todo (was 996d5e3).--no-edit accepts the default merge message (otherwise an editor opens).
Check yourself: When does Git create a merge commit?
If only one side moved, Git does a fast-forward instead.
Your first conflict (safely, on your own)
Both branches changed the same line. Git cannot choose, so it asks you — and you practise this alone first.
In one sentenceA conflict is Git asking “which version of this line do you want?”.
Your version
Their version
The file now
$ git switch -c feature/title
Switched to a new branch 'feature/title'
$ sed -i '1s/.*/# First Commit: my Git diary/' README.md
$ git commit -am "Rename the title"
[feature/title df0f8a5] Rename the title
1 file changed, 1 insertion(+), 1 deletion(-)
$ git switch main
Switched to branch 'main'
$ sed -i '1s/.*/# First Commit (practice)/' README.md
$ git commit -am "Mark as practice"
[main 6c07fdf] Mark as practice
1 file changed, 1 insertion(+), 1 deletion(-)
$ git merge feature/title
Auto-merging README.md
CONFLICT (content): Merge conflict in README.md
Automatic merge failed; fix conflicts and then commit the result.
$ git status --short
UU README.md
$ cat README.md
<<<<<<< HEAD
# First Commit (practice)
=======
# First Commit: my Git diary
>>>>>>> feature/title
A small Git practice repository.
Learn the three areas.
Branches are cheap.Top half (up to =======) is your branch (HEAD), bottom half is the incoming branch. UU = unmerged.
Your version
Their version
The file now
$ sed -i '/^<<<<<<< /,/^>>>>>>> /c\# First Commit: my Git diary (practice)' README.md
$ head -1 README.md
# First Commit: my Git diary (practice)
$ git add README.md
$ git commit --no-edit
[main 37c29fe] Merge branch 'feature/title'
$ git log --oneline --graph -4
* 37c29fe Merge branch 'feature/title'
|\
| * df0f8a5 Rename the title
* | 6c07fdf Mark as practice
|/
* e6e6b44 Merge branch 'feature/todo'
|\
$ git branch -d feature/title
Deleted branch feature/title (was df0f8a5).Put work aside: stash
Half-finished edits but you need a clean folder? Stash them, do the other thing, bring them back.
In one sentencestash is a drawer for unfinished work.
$ echo 'half-finished idea' >> notes.md
$ git status --short
M notes.md
$ git stash push -m "idea in progress"
Saved working directory and index state On main: idea in progress
$ git status --short
$ git stash list
stash@{0}: On main: idea in progress
$ git stash pop
On branch main
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: notes.md
no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (277758e24b621bbf725ee197057555efce8d21e0)
$ git status --short
M notes.mdIn this animation the right column shows the stash drawer instead of the remote.
Milestone 2: branch, merge, conflict
Put stage 2 together in your diary repository.
🏁 Your tasks
A remote and a colleague: push, clone, pull, pull requests
A remote: the shared copy
Create a practice “server” on your own disk and connect it with the nickname origin.
In one sentenceA remote is another copy of the repository; origin is its usual nickname.
$ git init --bare ~/remote/first_commit.git
Initialized empty Git repository in /home/alex/remote/first_commit.git/
$ git remote add origin ~/remote/first_commit.git
$ git remote -v
origin /home/alex/remote/first_commit.git (fetch)
origin /home/alex/remote/first_commit.git (push)A bare repository has no working folder — exactly what a server keeps. With a real server only the address differs: git remote add origin git@github.com:team/first_commit.git.
Push: send your commits
git push copies your commits to the remote. The first time, -u links your main to origin/main.
In one sentencepush uploads commits; -u sets the upstream once.
$ git push -u origin main
To /home/alex/remote/first_commit.git
* [new branch] main -> main
branch 'main' set up to track 'origin/main'.
$ git status
On branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree clean- ✅ your commits that the server does not have yet
- ✅ the branch: the server’s main moves to your newest commit
- ❌ files you changed but did not commit
- ❌ what is only staged (on the tray)
- ❌ untracked files
So: add → commit → push. No commit, nothing to push. Before pushing, git status says “ahead of origin/main by N commits” and git log --oneline origin/main..main lists exactly what will travel.
Fix it before you push: amend and reset --soft
Your newest commits stay private until you push. Until then you may still change them. After the push: never rewrite — add a new commit.
In one sentenceBefore the push you may rewrite your last commit; after the push you add a new one.
$ echo 'Weather: rainy' > weather.txt
$ git commit -am "Updte weather"
[main 66f755a] Updte weather
1 file changed, 1 insertion(+), 1 deletion(-)
$ git status
On branch main
Your branch is ahead of 'origin/main' by 1 commit.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
$ git log --oneline origin/main..main
66f755a Updte weather
$ git commit --amend -m "Update weather"
[main 8ccc841] Update weather
Date: Mon Oct 12 10:37:00 2026 +0000
1 file changed, 1 insertion(+), 1 deletion(-)
$ git log --oneline -2
8ccc841 Update weather
bad5093 Merge pull request: comics page
$ echo 'Temperature: 12 C' >> weather.txt
$ git add weather.txt
$ git commit --amend --no-edit
[main 479b2e3] Update weather
Date: Mon Oct 12 10:37:00 2026 +0000
1 file changed, 2 insertions(+), 1 deletion(-)
$ git show --stat --format="%h %s" HEAD
479b2e3 Update weather
weather.txt | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
$ git reset --soft HEAD~1
$ git status --short
M weather.txt
$ git log --oneline -1
bad5093 Merge pull request: comics page
$ git commit -m "Update the weather report"
[main d1781a3] Update the weather report
1 file changed, 2 insertions(+), 1 deletion(-)
$ git push
To /home/maya/practice.git
bad5093..d1781a3 main -> main
$ git status
On branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree cleanThe practice copy of Maya’s newspaper. --amend never edits a commit — it replaces it with a new one (new id).
$ git commit --amend -m "Weather report"
[main a0290e4] Weather report
Date: Mon Oct 12 10:49:00 2026 +0000
1 file changed, 2 insertions(+), 1 deletion(-)
$ git status
On branch main
Your branch and 'origin/main' have diverged,
and have 1 and 1 different commits each, respectively.
(use "git pull" if you want to integrate the remote branch with yours)
nothing to commit, working tree clean
$ git push
To /home/maya/practice.git
! [rejected] main -> main (non-fast-forward)
error: failed to push some refs to '/home/maya/practice.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. If you want to integrate the remote changes,
hint: use 'git pull' before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
$ git reset --hard origin/main
HEAD is now at d1781a3 Update the weather report
$ git status
On branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree cleangit reset --hard also throws away uncommitted changes on your desk. Use it only when you really want the server’s version.
| Situation | Command | OK? |
|---|---|---|
| Typo in the last message, not pushed | git commit --amend -m "Better message" | yes |
| Forgot a file or a change, not pushed | git add FILE → git commit --amend --no-edit | yes |
| Want to redo the last commit completely, not pushed | git reset --soft HEAD~1 (changes stay staged) | yes |
| Is it pushed already? | git status (“ahead of …”) or git log origin/main..main | check first |
| Already pushed and wrong | a new commit, or git revert COMMIT | yes |
| Already pushed: amend + force push | git push --force | no — breaks everybody else’s copy |
Check yourself: git status says “Your branch is ahead of 'origin/main' by 1 commit”. May you still amend it?
“ahead” means the commit exists only on your computer, so rewriting it harms nobody.
Sam joins: clone
A colleague does not init — git clone downloads the whole history and sets up origin automatically.
In one sentenceclone = download everything + connect origin.
$ git clone /home/alex/remote/first_commit.git first_commit
Cloning into 'first_commit'...
done.
$ cd first_commit
$ git log --oneline -3
37c29fe Merge branch 'feature/title'
6c07fdf Mark as practice
df0f8a5 Rename the title
$ git remote -v
origin /home/alex/remote/first_commit.git (fetch)
origin /home/alex/remote/first_commit.git (push)
$ git status
On branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree cleanGet colleagues’ work: fetch and pull
Sam pushed commit D. fetch downloads it without touching your files; pull downloads and updates your branch.
In one sentencefetch = look; pull = look and take.
$ git fetch
From /home/alex/remote/first_commit
37c29fe..7c146f5 main -> origin/main
$ git status
On branch main
Your branch is behind 'origin/main' by 1 commit, and can be fast-forwarded.
(use "git pull" to update your local branch)
nothing to commit, working tree clean
$ git log --oneline main..origin/main
7c146f5 Add a line from Sam
$ git diff --stat main origin/main
README.md | 1 +
1 file changed, 1 insertion(+)$ git pull
Updating 37c29fe..7c146f5
Fast-forward
README.md | 1 +
1 file changed, 1 insertion(+)
$ git log --oneline -2
7c146f5 Add a line from Sam
37c29fe Merge branch 'feature/title'Check yourself: You want to see what colleagues pushed, without changing your files. Which command?
git fetch only moves origin/main.
Both of you committed: rejected push
Sam and Alex changed the same line and both committed. Alex pushes second — Git refuses, so nothing of Sam’s is lost.
In one sentenceA rejected push protects commits you have not seen yet; your branch has diverged.
$ git push
To /home/alex/remote/first_commit.git
! [rejected] main -> main (fetch first)
error: failed to push some refs to '/home/alex/remote/first_commit.git'
hint: Updates were rejected because the remote contains work that you do not
hint: have locally. This is usually caused by another repository pushing to
hint: the same ref. If you want to integrate the remote changes, use
hint: 'git pull' before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.This is protection, not a failure.
$ git pull
From /home/alex/remote/first_commit
7c146f5..d6704c9 main -> origin/main
hint: You have divergent branches and need to specify how to reconcile them.
hint: You can do so by running one of the following commands sometime before
hint: your next pull:
hint:
hint: git config pull.rebase false # merge
hint: git config pull.rebase true # rebase
hint: git config pull.ff only # fast-forward only
hint:
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
fatal: Need to specify how to reconcile divergent branches.Git 2.27+ wants you to choose how to combine diverged branches. For beginners: git pull --no-rebase (merge), or set it once with git config --global pull.rebase false.
Resolve a conflict with a colleague
Same steps as your solo conflict — the other side is just Sam’s commit now.
In one sentencePull, fix the marked lines, add, commit, push.
Your version
Their version
The file now
$ git pull --no-rebase
Auto-merging README.md
CONFLICT (content): Merge conflict in README.md
Automatic merge failed; fix conflicts and then commit the result.
$ git status --short
UU README.md
$ sed -n '3,7p' README.md
<<<<<<< HEAD
A small Git practice repository, step by step.
=======
A small Git practice repository for the whole team.
>>>>>>> d6704c9d672e9f8e9b26ca5cc91e26b914373279$ sed -i '/^<<<<<<< /,/^>>>>>>> /c\A small Git practice repository for the whole team, step by step.' README.md
$ sed -n '3p' README.md
A small Git practice repository for the whole team, step by step.
$ git add README.md
$ git commit --no-edit
[main 774769f] Merge branch 'main' of /home/alex/remote/first_commit
$ git log --oneline --graph -4
* 774769f Merge branch 'main' of /home/alex/remote/first_commit
|\
| * d6704c9 Say who the repository is for
* | 2c470ac Say how we learn
|/
* 7c146f5 Add a line from Sam
$ git push
To /home/alex/remote/first_commit.git
d6704c9..774769f main -> mainThe merge commit joins your line of work and Sam’s; after git push Sam can pull it.
The team workflow: pull requests
How most teams work every day: branch, push, ask for review, merge on the server, update.
In one sentenceA pull request asks the team to review a branch before it joins main.
- Update main:
git switch main→git pull - Branch:
git switch -c feature/short-name - Small commits:
git status→git diff→git add→git commit - Publish:
git push -u origin feature/short-name - Pull request (GitHub, Gitea) / merge request (GitLab) on the server’s web page
- Review: more commits on the same branch,
git push - Merge on the server, then update locally (below)
$ git switch -c feature/faq
Switched to a new branch 'feature/faq'
$ printf '# FAQ\n\nAsk your team.\n' > FAQ.md
$ git add FAQ.md
$ git commit -m "Add FAQ"
[feature/faq d324cac] Add FAQ
1 file changed, 3 insertions(+)
create mode 100644 FAQ.md
$ git push -u origin feature/faq
To /home/alex/remote/first_commit.git
* [new branch] feature/faq -> feature/faq
branch 'feature/faq' set up to track 'origin/feature/faq'.$ git switch main
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
$ git pull
From /home/alex/remote/first_commit
774769f..4b6c4bf main -> origin/main
Updating 774769f..4b6c4bf
Fast-forward
FAQ.md | 3 +++
1 file changed, 3 insertions(+)
create mode 100644 FAQ.md
$ git fetch --prune
From /home/alex/remote/first_commit
- [deleted] (none) -> origin/feature/faq
$ git branch -d feature/faq
Deleted branch feature/faq (was d324cac).
$ git log --oneline --graph -3
* 4b6c4bf Merge pull request: Add FAQ
|\
| * d324cac Add FAQ
|/
* 774769f Merge branch 'main' of /home/alex/remote/first_commit
|\--prune removes the origin/feature/faq label because the branch was deleted on the server.
Check yourself: Your pull request was merged on the server. What next?
Update main with the merged work, then delete the old branch.
Milestone 3: team up with yourself
Simulate a team with two folders on your computer.
🏁 Your tasks
Revert, reset, reflog rescue, rebase, tags
Which undo? A map
Different mistakes need different tools. Pick by asking: is it pushed already?
In one sentencePushed → revert. Not pushed → reset or amend. Lost → reflog.
| I want to … | Command | Safe after push? |
|---|---|---|
| throw away edits in a file | git restore FILE | yes (local only) |
| take a file off the tray | git restore --staged FILE | yes (local only) |
| fix the last commit | git commit --amend | no — before pushing only |
| undo a pushed commit | git revert COMMIT | yes — adds an “opposite” commit |
| take back the last local commit, keep the changes | git reset --soft HEAD~1 | no — before pushing only |
| find a commit I “lost” | git reflog | yes (read-only) |
Undo a pushed commit: revert
revert adds a new commit that is the exact opposite. Nothing is erased, so colleagues’ history stays intact.
In one sentencerevert = a new commit that cancels an old one.
$ git log --oneline -1
5244bfa Add a wrong line
$ git revert --no-edit HEAD
[main 4899c98] Revert "Add a wrong line"
Date: Thu Oct 1 09:42:02 2026 +0000
1 file changed, 1 deletion(-)
$ git log --oneline -3
4899c98 Revert "Add a wrong line"
5244bfa Add a wrong line
4b6c4bf Merge pull request: Add FAQ
$ git push
To /home/alex/remote/first_commit.git
5244bfa..4899c98 main -> mainTake back a local commit: reset --soft
Not pushed yet? reset moves the branch back; --soft keeps the changes staged so nothing is lost.
In one sentencereset --soft = “un-commit”, keep the work.
$ echo '- wrong idea' >> todo.txt
$ git commit -am "Wrong idea"
[main 8e95949] Wrong idea
1 file changed, 1 insertion(+)
$ git reset --soft HEAD~1
$ git status --short
M todo.txt
$ git log --oneline -1
4899c98 Revert "Add a wrong line"The safety net: reflog
Even after reset --hard, the commit still exists. reflog remembers every place HEAD has been.
In one sentencereflog finds “lost” commits; HEAD@{1} means “one move ago”.
$ echo '- important' >> todo.txt
$ git commit -am "Important work"
[main 26af533] Important work
1 file changed, 1 insertion(+)
$ git reset --hard HEAD~1
HEAD is now at 4899c98 Revert "Add a wrong line"
$ git log --oneline -1
4899c98 Revert "Add a wrong line"
$ git reflog -3
4899c98 HEAD@{0}: reset: moving to HEAD~1
26af533 HEAD@{1}: commit: Important work
4899c98 HEAD@{2}: reset: moving to HEAD~1
$ git reset --hard HEAD@{1}
HEAD is now at 26af533 Important work
$ git log --oneline -1
26af533 Important workCheck yourself: You ran git reset --hard by mistake. First step?
The old commit is still in reflog (for weeks by default).
Rebase: replay your commits on top
Instead of a merge commit, git rebase main re-applies your branch’s commits on the newest main — a straight line.
In one sentencerebase rewrites your commits as if you had started from the newest main.
$ git switch -c feature/tips
Switched to a new branch 'feature/tips'
$ echo '- git stash keeps work aside' >> notes.md
$ git commit -am "Add a stash tip"
[feature/tips 06f8457] Add a stash tip
1 file changed, 1 insertion(+)
$ git log --oneline --graph --all -3
* 651387a Update README on main
| * 06f8457 Add a stash tip
|/
* 26af533 Important work
$ git rebase main
Rebasing (1/1)
Successfully rebased and updated refs/heads/feature/tips.
$ git log --oneline --graph --all -3
* c50cc06 Add a stash tip
* 651387a Update README on main
* 26af533 Important workCompare the commit id before and after: rebase creates new commits.
Mark releases: tags
A tag is a permanent name for one commit, usually a version number.
In one sentenceA tag is a bookmark that never moves.
$ git tag -a v1.0 -m "First version"
$ git tag
v1.0
$ git show v1.0 --stat --format="%h %s"
tag v1.0
Tagger: Alex Example <alex@example.com>
First version
c50cc06 Add a stash tip
notes.md | 1 +
1 file changed, 1 insertion(+)
$ git push origin v1.0
To /home/alex/remote/first_commit.git
* [new tag] v1.0 -> v1.0“Oh no!” — quick fixes
The most common “I messed up” moments and the exact fix.
I committed with a typo in the message
Not pushed: git commit --amend -m "Better message". Pushed: leave it.
I forgot a file in the last commit
git add forgotten.txt, then git commit --amend --no-edit (before pushing).
I committed to main but wanted a branch
git branch my-feature, git reset --hard HEAD~1, git switch my-feature (before pushing).
I need to undo a pushed commit
git revert COMMIT, then git push.
A reset went wrong / I deleted something
git reflog, then git reset --hard HEAD@{N} or git switch -c rescue HEAD@{N}.
I need just one commit from another branch
git cherry-pick COMMIT copies it onto your branch.
I committed a password
Change the password first — it is in the history. Then remove the file, add it to .gitignore, and ask the repository owner about cleaning history.
I want the server’s version back
git fetch, then git reset --hard origin/main — throws away local commits and edits (stash first).
I am stuck in a merge or rebase
git merge --abort or git rebase --abort.
Troubleshooting: real error messages
The messages beginners meet most often, exactly as Git prints them.
$ git add f
$ git commit -m "first"
Author identity unknown
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: empty ident name (for <newuser@laptop.(none)>) not allowedFix: the two git config --global lines from setup.
$ git status
fatal: not a git repository (or any of the parent directories): .gitYou are not inside the project. Fix: pwd, then cd into it.
$ git switch --detach HEAD~1
HEAD is now at 651387a Update README on main
$ git status
HEAD detached at 651387a
nothing to commit, working tree clean
$ git switch main
Previous HEAD position was 651387a Update README on main
Switched to branch 'main'
Your branch is up to date with 'origin/main'.You are looking at an old commit (detached HEAD). Fix: git switch main, or git switch -c new-branch to keep work made there.
| Message | Meaning | Fix |
|---|---|---|
! [rejected] … (fetch first) | the remote has commits you lack | git pull --no-rebase, then push (lesson) |
Need to specify how to reconcile divergent branches | both sides committed | git pull --no-rebase |
CONFLICT (content) | same lines changed | edit, add, commit (lesson) |
Permission denied (publickey) | the server does not know your key | add your .pub key (lesson) |
Your local changes would be overwritten | unsaved edits block switch/pull | commit or git stash |
Milestone 4: break it and fix it
Practise every rescue on purpose.
🏁 Your tasks
SSH keys, good messages, settings
Log like a pro: graphs, filters and formats
Every useful git log option on one page, with real output from a repository with branches, a merge and a tag.
In one sentencegit log can draw the map of all branches, filter by person, text, date or file, and print any format you like.
| I want to see … | Option |
|---|---|
| the map of all branches | git log --oneline --graph --all --decorate |
| only the last N | -N e.g. -3 |
| one person’s commits | --author=Leo |
| messages containing a word | --grep=weather -i |
| when a text appeared / disappeared in the files | -S "Rain all week" |
| a date range | --after="2026-10-12 00:00" --before="2026-10-13 23:59" |
| one file’s history | -- sports.txt (add --follow for renamed files) |
| merges only / no merges / main line only | --merges · --no-merges · --first-parent |
| what is in B but not in A | A..B e.g. origin/main..main |
| files changed | --stat · --name-status |
| the exact changes | -p |
| my own layout | --pretty=format:"%h %an %ad %s" --date=short |
| oldest first | --reverse |
| commits per person / who wrote each line | git shortlog -sn · git blame FILE |
📖 How to read the graph: what do * and | mean?
* = one commit (one drawer)| = a line of history, going down to OLDER commits\ / = two lines split apart or join togetherNewest is at the TOP. Each * is on the line (column) its branch uses: here the left line = main, the right line = sports.
| # | the real output | what it means |
|---|---|---|
| 1 | * d9a6948 (HEAD -> main, tag: v1.0) Merge sports page | NEWEST commit (d9a6948): a MERGE. It joins the two lines you see below it. The branch main and the tag v1.0 point here, and HEAD = you are on main. |
| 2 | |\ | The line SPLITS into two. Why? The merge above has two parents: the left line is main, the right line is sports. |
| 3 | | * 3430c2d (sports) Add chess result | RIGHT line (sports): Leo’s newest commit 3430c2d. The sports name tag is here. The “|” on the left only means: main’s line continues past it. |
| 4 | | * 00dd761 Add football score | RIGHT line (sports): Leo’s first commit 00dd761, one step older. |
| 5 | * | f530647 Add weekly forecast | LEFT line (main): Maya’s commit f530647, made while Leo was working on sports. The “|” on the right: sports’ line continues past it. |
| 6 | |/ | The right line JOINS the left one again: this is where sports started (it grew out of the commit just below). |
| 7 | * d1781a3 (origin/main, origin/HEAD) Update the weather report | The commit where both lines began (d1781a3). origin/main (the server’s main) is still here — nothing above it is pushed yet. |
The story, read from the BOTTOM up:
- Everybody starts from d1781a3 (row 7).
- Leo makes the sports branch and adds two commits: 00dd761, then 3430c2d (rows 4 and 3).
- At the same time Maya adds f530647 on main (row 5).
- Maya merges sports into main: d9a6948 (row 1) joins both lines. Done — main now contains everything.
$ git log --oneline --graph --all --decorate
* d9a6948 (HEAD -> main, tag: v1.0) Merge sports page
|\
| * 3430c2d (sports) Add chess result
| * 00dd761 Add football score
* | f530647 Add weekly forecast
|/
* d1781a3 (origin/main, origin/HEAD) Update the weather report
* bad5093 Merge pull request: comics page
|\
| * cf50ef4 Add comics page
|/
* d604b22 Update headline
* b5597bc Add school trip story
* d201aa6 Add photo note
* 52e7ae3 First edition
$ git log --graph --all --color=always --pretty=format:'%C(yellow)%h%C(reset) %C(green)%ad%C(reset) %C(bold blue)%an%C(reset)%C(auto)%d%C(reset) %s' --date=short
* d9a6948 2026-10-14 Maya Editor (HEAD -> main, tag: v1.0) Merge sports page
|\
| * 3430c2d 2026-10-13 Leo Sports (sports) Add chess result
| * 00dd761 2026-10-13 Leo Sports Add football score
* | f530647 2026-10-14 Maya Editor Add weekly forecast
|/
* d1781a3 2026-10-12 Maya Editor (origin/main, origin/HEAD) Update the weather report
* bad5093 2026-10-11 Leo Sports Merge pull request: comics page
|\
| * cf50ef4 2026-10-10 Maya Editor Add comics page
|/
* d604b22 2026-10-09 Maya Editor Update headline
* b5597bc 2026-10-07 Leo Sports Add school trip story
* d201aa6 2026-10-05 Maya Editor Add photo note
* 52e7ae3 2026-10-03 Maya Editor First edition$ git lg
* d9a6948 (HEAD -> main, tag: v1.0) Merge sports page
|\
| * 3430c2d (sports) Add chess result
| * 00dd761 Add football score
* | f530647 Add weekly forecast
|/
* d1781a3 (origin/main, origin/HEAD) Update the weather report
* bad5093 Merge pull request: comics page
|\
| * cf50ef4 Add comics page
|/
* d604b22 Update headline
* b5597bc Add school trip story
* d201aa6 Add photo note
* 52e7ae3 First editionColours: %C(yellow), %C(green), %C(bold blue), %C(auto) for the name tags. Save your favourite as an alias: git config --global alias.lg "log --graph --oneline --all --decorate" — see Your .gitconfig for a whole set.
$ git log --oneline -3
d9a6948 Merge sports page
f530647 Add weekly forecast
3430c2d Add chess result
$ git log --oneline --author=Leo
3430c2d Add chess result
00dd761 Add football score
bad5093 Merge pull request: comics page
b5597bc Add school trip story
$ git log --oneline -i --grep=weather
d1781a3 Update the weather report
$ git log --oneline -S "Rain all week"
f530647 Add weekly forecast
$ git log --oneline --after="2026-10-12 00:00" --before="2026-10-13 23:59"
3430c2d Add chess result
00dd761 Add football score
d1781a3 Update the weather report
$ git log --oneline -- sports.txt
3430c2d Add chess result
00dd761 Add football score
52e7ae3 First edition
$ git log --oneline --merges
d9a6948 Merge sports page
bad5093 Merge pull request: comics page
$ git log --oneline --no-merges -4
f530647 Add weekly forecast
3430c2d Add chess result
00dd761 Add football score
d1781a3 Update the weather report
$ git log --oneline --first-parent -4
d9a6948 Merge sports page
f530647 Add weekly forecast
d1781a3 Update the weather report
bad5093 Merge pull request: comics page
$ git log --oneline HEAD~3..HEAD
d9a6948 Merge sports page
f530647 Add weekly forecast
3430c2d Add chess result
00dd761 Add football score
d1781a3 Update the weather reportHEAD~3..HEAD shows 5 commits, not 3: the range also contains the sports commits that came in with the merge. Ranges mean “reachable from B but not from A”.
$ git log --stat -1 sports
commit 3430c2de8b0787cd3927ffb35dbb8f4e8150ff5b
Author: Leo Sports <leo@school.example>
Date: Tue Oct 13 10:01:00 2026 +0000
Add chess result
sports.txt | 1 +
1 file changed, 1 insertion(+)
$ git log --oneline --name-status -3
d9a6948 Merge sports page
f530647 Add weekly forecast
M weather.txt
3430c2d Add chess result
M sports.txt
$ git log -p --oneline -1 -- weather.txt
f530647 Add weekly forecast
diff --git a/weather.txt b/weather.txt
index cd0ab2b..3a0d2a2 100644
--- a/weather.txt
+++ b/weather.txt
@@ -1,2 +1,3 @@
Weather: rainy
Temperature: 12 C
+Rain all week
$ git show --stat --format="%h %s" v1.0
tag v1.0
Tagger: Maya Editor <maya@school.example>
Edition 1.0
d9a6948 Merge sports page
sports.txt | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)$ git log --pretty=format:"%h | %an | %ad | %s" --date=format:"%d %b %H:%M" -4
d9a6948 | Maya Editor | 14 Oct 10:05 | Merge sports page
f530647 | Maya Editor | 14 Oct 10:04 | Add weekly forecast
3430c2d | Leo Sports | 13 Oct 10:01 | Add chess result
00dd761 | Leo Sports | 13 Oct 10:59 | Add football score$ git log --reverse --oneline -3
3430c2d Add chess result
f530647 Add weekly forecast
d9a6948 Merge sports page
$ git shortlog -sn --all
7 Maya Editor
4 Leo Sports
$ git blame weather.txt
d1781a39 (Maya Editor 2026-10-12 10:49:00 +0000 1) Weather: rainy
d1781a39 (Maya Editor 2026-10-12 10:49:00 +0000 2) Temperature: 12 C
f5306470 (Maya Editor 2026-10-14 10:04:00 +0000 3) Rain all weekConnect to a real server: SSH keys
Servers identify you with an SSH key. Create it once, give the server the public half.
In one sentenceAn SSH key is your personal key to the server; only the .pub half is shared.
$ ssh-keygen -t ed25519 -C "you@example.com"
# press Enter for the default file; choose a passphrase
$ cat ~/.ssh/id_ed25519.pub
# copy this ONE line into the server: Settings → SSH keys
$ ssh -T git@github.com
# the server greets you by name when it works
$ git remote set-url origin git@github.com:team/first_commit.git
$ git pushThese depend on your server, so no captured output is shown.
Write commit messages people love
Future you (and your team) will read these. Make them useful.
In one sentenceA good commit message says what and why in one short line.
✅ Good
Fix login timeout on slow networksAdd FAQ pageRemove unused config option
❌ Not helpful
fixstuffchanges from Tuesday
Your .gitconfig: settings and shortcuts (aliases)
Git reads your personal settings from one small text file. Put your favourite long commands there as short nicknames.
In one sentence~/.gitconfig holds your settings; an alias turns a long command into a short one, like git lg or git hist.
| Where | File | Command |
|---|---|---|
| you, every repository on this computer | ~/.gitconfig (Windows: C:\Users\YOU\.gitconfig) | git config --global … |
| only this repository (wins over global) | .git/config | git config … |
| open the file in your editor | git config --global --edit | |
| see all settings and where each comes from | git config --list --show-origin |
$ cat ~/.gitconfig
[user]
name = Maya Editor
email = maya@school.example
[init]
defaultBranch = main
$ git config --global core.editor nano
$ git config --global pull.rebase false
$ git config --global push.autoSetupRemote true
$ git config --global fetch.prune true
$ git config --global color.ui auto
$ git config --global merge.conflictStyle zdiff3
$ git config --global alias.st "status -sb"
$ git config --global alias.last "log -1 HEAD --stat"
$ git config --global alias.lg "log --oneline --graph --all --decorate"
$ git config --global alias.hist "log --graph --date=short --pretty=format:'%h %ad | %s%d [%an]'"
$ git config --global alias.who "shortlog -sn --all"
$ git config --global alias.br "branch -a -vv"
$ git config --global alias.unstage "restore --staged"
$ cat ~/.gitconfig
[user]
name = Maya Editor
email = maya@school.example
[init]
defaultBranch = main
[core]
editor = nano
[pull]
rebase = false
[push]
autoSetupRemote = true
[fetch]
prune = true
[color]
ui = auto
[merge]
conflictStyle = zdiff3
[alias]
st = status -sb
last = log -1 HEAD --stat
lg = log --oneline --graph --all --decorate
hist = log --graph --date=short --pretty=format:'%h %ad | %s%d [%an]'
who = shortlog -sn --all
br = branch -a -vv
unstage = restore --staged
$ git config --get alias.hist
log --graph --date=short --pretty=format:'%h %ad | %s%d [%an]'
$ git config --show-origin user.email
file:/home/maya/.gitconfig maya@school.exampleEvery git config --global NAME VALUE adds a line under a [section]: alias.hist becomes hist = … under [alias]. You can also edit the file directly.
$ git st
## main...origin/main [ahead 4]
$ git lg
* d9a6948 (HEAD -> main, tag: v1.0) Merge sports page
|\
| * 3430c2d (sports) Add chess result
| * 00dd761 Add football score
* | f530647 Add weekly forecast
|/
* d1781a3 (origin/main, origin/HEAD) Update the weather report
* bad5093 Merge pull request: comics page
|\
| * cf50ef4 Add comics page
|/
* d604b22 Update headline
* b5597bc Add school trip story
* d201aa6 Add photo note
* 52e7ae3 First edition
$ git hist -6
* d9a6948 2026-10-14 | Merge sports page (HEAD -> main, tag: v1.0) [Maya Editor]
|\
| * 3430c2d 2026-10-13 | Add chess result (sports) [Leo Sports]
| * 00dd761 2026-10-13 | Add football score [Leo Sports]
* | f530647 2026-10-14 | Add weekly forecast [Maya Editor]
|/
* d1781a3 2026-10-12 | Update the weather report (origin/main, origin/HEAD) [Maya Editor]
* bad5093 2026-10-11 | Merge pull request: comics page [Leo Sports]
|\ $ git last
commit d9a694893b83d5de958c805c1b63930daeb79304
Merge: f530647 3430c2d
Author: Maya Editor <maya@school.example>
Date: Wed Oct 14 10:05:00 2026 +0000
Merge sports page
$ git who
7 Maya Editor
4 Leo Sports
$ git br
* main d9a6948 [origin/main: ahead 4] Merge sports page
sports 3430c2d Add chess result
remotes/origin/HEAD -> origin/main
remotes/origin/main d1781a3 Update the weather report
$ echo 'Windy' >> weather.txt
$ git add weather.txt
$ git st
## main...origin/main [ahead 4]
M weather.txt
$ git unstage weather.txt
$ git st
## main...origin/main [ahead 4]
M weather.txtgit st starts with ## main...origin/main [ahead 4]: your branch, its server branch and how far apart they are. git unstage is just git restore --staged.
# ~/.gitconfig — your personal Git settings (git config --global … writes here)
[user]
name = Your Name
email = you@example.com
[init]
defaultBranch = main # new repositories start on main
[core]
editor = nano # editor for commit messages (or: code --wait, notepad, vim)
autocrlf = true # Windows only: CRLF on disk, LF in the repository (macOS/Linux: input)
[pull]
rebase = false # plain “git pull” merges instead of asking
[push]
autoSetupRemote = true # first push of a new branch needs no “-u origin NAME”
[fetch]
prune = true # forget branches that were deleted on the server
[color]
ui = auto # colours in the terminal
[merge]
conflictStyle = zdiff3 # conflict markers also show the original text
[diff]
colorMoved = zebra # moved lines get their own colour
[log]
date = iso # dates like 2026-10-14 10:05:00 +0000
[help]
autocorrect = prompt # “git stauts” → asks: did you mean “status”?
[rerere]
enabled = true # remember how you solved a conflict, reuse it next time
[alias]
# --- look ---
st = status -sb # short status + branch line
lg = log --oneline --graph --all --decorate # the map of all branches
hist = log --graph --date=short --pretty=format:'%h %ad | %s%d [%an]'
lgc = log --graph --all --pretty=format:'%C(yellow)%h%C(reset) %C(green)%ad%C(reset) %C(bold blue)%an%C(reset)%C(auto)%d%C(reset) %s' --date=short
last = log -1 HEAD --stat # the newest commit with its files
who = shortlog -sn --all # commits per person
today = log --since=midnight --oneline --author='Your Name'
unpushed = log --oneline @{u}.. # commits not pushed yet
incoming = log --oneline ..@{u} # fetched but not merged yet
br = branch -a -vv # all branches, ahead/behind
# --- do ---
co = switch
cob = switch -c
unstage = restore --staged # take a file off the tray
amend = commit --amend --no-edit # add the tray to the last commit (before push!)
undo = reset --soft HEAD~1 # un-commit, keep the changes staged
| Setting | What it does |
|---|---|
user.name, user.email | written on every commit you make |
init.defaultBranch main | new repositories start on main |
core.editor | the editor that opens for commit messages (nano, "code --wait", notepad) |
core.autocrlf | line endings: true on Windows, input on macOS/Linux |
pull.rebase false | git pull merges instead of asking you to choose |
push.autoSetupRemote true | the first push of a new branch works without -u origin NAME |
fetch.prune true | deleted server branches disappear from your list automatically |
color.ui auto | colours in the terminal |
merge.conflictStyle zdiff3 | conflict markers also show the original text — easier to decide |
diff.colorMoved zebra | moved lines are coloured differently from added/removed ones |
log.date iso | the date format for git log |
help.autocorrect prompt | typos like git stauts ask “did you mean status?” |
rerere.enabled true | Git remembers how you solved a conflict and reuses it |
alias.NAME "…" | your own shortcut: git NAME runs the long command |
Milestone 5: you are ready
The final check.
🏁 Your tasks
🎉 When all are ticked, you know more Git than most people who use it every day.
Playground and more
Git playground: type and watch
Try commands and watch the graph change — nothing can break. Lessons send you here with a ready-made situation.
Commands: git commit · git branch NAME · git switch NAME · git switch -c NAME · git merge NAME · git rebase NAME · git log · reset
Start from:
Challenges
- Make two commits on
main. - Create
feature, commit on it, merge it intomain. - Get a real merge commit (both branches moved).
- Rebase
featureontomain.
Where to go next
Good, free places to keep learning.
Pro Git (official book)
git-scm.com/book — the complete reference.
Learn Git Branching
learngitbranching.js.org — more branching puzzles.
Oh Shit, Git!?!
ohshitgit.com — recipes for getting unstuck.
Oh My Git!
An open-source game that shows Git’s insides.
Built-in help
git help commit or git commit -h.
Your team
Ask for the rules: branch names, messages, reviews.
Cheat sheet and glossary
Cheat sheet
Everything on one screen.
Set up
git config --global user.name "Name"- your name on commits
git init- start a repository
git clone URL- copy one
Look
git status- what changed
git diff- desk changes
git diff --staged- tray changes
git log --oneline --graph --all- history
git show COMMIT- one commit
Save
git add FILE- stage
git commit -m "msg"- save a snapshot
git push- send to the remote
Branch
git switch -c NAME- new branch
git switch NAME- go there
git merge NAME- bring it in
git branch -d NAME- delete merged branch
Sync
git fetch- download, do not touch files
git pull- download and update
git push -u origin NAME- publish a branch
Undo
git restore FILE- discard edits
git restore --staged FILE- unstage
git commit --amend- fix last commit
git revert COMMIT- undo a pushed commit
git reset --soft HEAD~1- un-commit
git reflog- find lost commits
Glossary — 70 terms
Every Git word used in this course, in plain language. Dotted words in the lessons show these definitions when you point at them.
add basics
Put changes on the staging area so they go into the next commit.
🧒 Put it in the backpack.
git add README.md
alias config
Your own short name for a longer Git command.
🧒 A nickname for a command.
git config --global alias.lg "log --oneline --graph"
amend undo
Replace the last commit with a corrected one (new message and/or forgotten files).
🧒 Fix the last snapshot before anyone saw it.
git commit --amend -m "Better message"
author basics
The person recorded in a commit (name and e-mail from git config).
🧒 Whose name is on the snapshot.
git log -1
bare repository remote
A repository without a working folder; servers store repositories this way.
🧒 The shared locker itself — nobody works inside it.
git init --bare ~/remote/first_commit.git
bisect history
Binary search through history to find the commit that introduced a bug.
🧒 Play “hot or cold” with commits.
git bisect start
blame history
Shows, line by line, which commit last changed each line of a file.
🧒 Who wrote this line?
git blame README.md
branch branching
A movable label that points at a commit and moves forward when you commit.
🧒 A copy to try something without touching the original.
git switch -c feature/notes
checkout branching
The older all-in-one command for switching branches and restoring files; today use git switch and git restore.
🧒 The old way to switch.
git checkout main
cherry-pick history
Copy one commit from another branch onto the current branch.
🧒 Take just that one change.
git cherry-pick COMMIT
clean working tree basics
No changes compared with the last commit: everything is saved.
🧒 Nothing to save right now.
git status → nothing to commit, working tree clean
clone remote
Download a complete copy of a repository, with all history, and set up origin.
🧒 Copy the whole chest of drawers, not just one drawer.
git clone URL
commit basics
A saved snapshot of the staged changes, with a message, an author and a unique id.
🧒 A drawer with a copy of your project and a label on it.
git commit -m "Add README"
commit id basics
The unique name of a commit (a SHA-1 hash); the first 7 characters are usually enough.
🧒 The number on the drawer.
git show 494f845
commit message basics
The short text that says what a commit does and why.
🧒 The label on the drawer.
git commit -m "Fix login timeout"
config config
Git settings, stored per computer (--global) or per repository.
🧒 Git’s settings screen.
git config --global --list
conflict branching
Both sides changed the same lines; Git stops and asks you to choose.
🧒 Two friends edited the same sentence.
CONFLICT (content): Merge conflict in README.md
conflict markers branching
The lines <<<<<<<, ======= and >>>>>>> that Git writes around both versions of a conflict.
🧒 The arrows around both versions.
<<<<<<< HEAD … ======= … >>>>>>> feature/title
detached HEAD branching
HEAD points directly at a commit instead of a branch; new commits there belong to no branch.
🧒 Looking into an old drawer without a name tag.
git switch --detach HEAD~1
diff basics
The exact line changes between two states (added + lines, removed - lines).
🧒 The highlighter view: what changed.
git diff
diverged remote
Your branch and its remote both have commits the other does not have.
🧒 You and your friend both wrote new pages.
Your branch and 'origin/main' have diverged
fast-forward branching
A merge where Git only moves the branch label forward, because nothing else changed; no merge commit.
🧒 Just skip ahead to the newest page.
git merge feature/notes → Fast-forward
fetch remote
Download new commits from the remote and update origin/… labels, without touching your files.
🧒 Peek into the shared locker.
git fetch
fork workflow
A server-side copy of someone else’s repository under your account (GitHub/GitLab feature, not a Git command).
🧒 Your own copy of someone’s project.
(button on the server’s web page)
.git folder internals
The hidden folder inside a repository that holds all history and settings.
🧒 Where the time machine lives.
ls -a
.gitignore basics
A file listing paths Git must not track (secrets, logs, build output).
🧒 The “do not pack” list.
printf '.env\n*.log\n' > .gitignore
HEAD basics
Where you are now: normally the current branch, which points at its newest commit.
🧒 The “you are here” sticker.
git log --oneline -1
HEAD@{n} undo
A position of HEAD n moves ago, as listed by git reflog.
🧒 Where you were n steps ago.
git reset --hard HEAD@{1}
HEAD~1 undo
The commit before HEAD (HEAD~2 is two back).
🧒 One drawer below.
git reset --soft HEAD~1
hunk basics
One block of changes in a diff, starting with @@.
🧒 One highlighted paragraph.
@@ -1,3 +1,4 @@
init basics
Turn the current folder into a Git repository (creates .git).
🧒 Start the time machine here.
git init
log history
The list of commits, newest first.
🧒 The list of all saves.
git log --oneline --graph --all
main branching
The usual name of the default branch (older repositories use master).
🧒 The original story.
git switch main
merge branching
Join another branch into the current one.
🧒 Glue the copy back into the original.
git merge feature/notes
merge commit branching
A commit with two parents that joins two lines of history.
🧒 The page that staples two chapters together.
Merge made by the 'ort' strategy.
merge request workflow
GitLab’s name for a pull request.
🧒 Please look at my changes and add them.
(web page on GitLab)
modified basics
A tracked file that changed since the last commit.
🧒 Changed but not yet saved.
M README.md
object internals
How Git stores data internally: blobs (file contents), trees (folders), commits and tags.
🧒 Git’s filing system.
git cat-file -p HEAD
origin remote
The default nickname of the remote you cloned from or added.
🧒 The shared locker’s name tag.
git remote -v
origin/main remote
Your local copy of where main is on the remote, updated by fetch/pull/push (a remote-tracking branch).
🧒 Your note of what the locker had last time you looked.
git log main..origin/main
ort internals
The name of Git’s default merge strategy (“Ostensibly Recursive’s Twin”).
🧒 Git’s merging engine.
Merge made by the 'ort' strategy.
parent history
The commit a commit was built on; merge commits have two parents.
🧒 The drawer below it.
git log --graph
prune remote
Remove origin/… labels of branches that were deleted on the remote.
🧒 Throw away old notes about empty lockers.
git fetch --prune
pull remote
Fetch and then merge (or rebase) the remote branch into yours.
🧒 Take the newest stuff out of the locker.
git pull
pull request workflow
A request on the server (GitHub, Gitea) to review a branch and merge it.
🧒 Please check my work and add it.
(web page on the server)
rebase history
Re-apply your commits on top of another commit, creating new commits: a straight history.
🧒 Rewrite your draft as if you started from the newest version.
git rebase main
ref internals
A name that points at a commit: branches, tags, HEAD, origin/main.
🧒 A name tag on a drawer.
git show-ref
reflog undo
A local diary of every position of HEAD; the way to find “lost” commits.
🧒 Git’s secret security camera.
git reflog
remote remote
Another copy of the repository, usually on a server, that you push to and fetch from.
🧒 The shared locker.
git remote add origin URL
repository basics
A project folder plus its complete history (kept in .git).
🧒 The folder with a time machine.
git init
reset undo
Move the current branch to another commit; --soft keeps changes staged, --hard throws them away.
🧒 Go back to an earlier save.
git reset --soft HEAD~1
restore undo
Throw away unsaved edits in a file, or (with --staged) take a file off the staging area.
🧒 Rub out scribbles since the last drawer.
git restore README.md
revert undo
Make a new commit that undoes an earlier one; safe for shared history.
🧒 Add a page saying “ignore that page”.
git revert HEAD
root commit history
The very first commit of a repository (it has no parent).
🧒 The very first drawer.
[main (root-commit) …] Add README
show history
Display one commit: its message and its changes.
🧒 Open one drawer and look inside.
git show HEAD
snapshot basics
The full state of the project saved by a commit.
🧒 What is inside a drawer: a copy of every file.
git commit
SSH key remote
A key pair used to log in to Git servers; you give the server only the public half (.pub).
🧒 Your personal key to the locker room.
ssh-keygen -t ed25519
staged basics
Changes put on the staging area with git add; they go into the next commit.
🧒 In the backpack.
A todo.txt
staging area basics
The list of changes that will go into the next commit (also called the index).
🧒 The backpack you pack before the trip.
git status
stash undo
Put unfinished changes aside and get a clean folder; bring them back later.
🧒 The drawer for unfinished work.
git stash / git stash pop
status basics
Shows the current branch and which files are changed, staged or untracked.
🧒 Where am I, and what is unsaved?
git status
switch branching
Move to another branch (your files change to that branch’s version).
🧒 Pick up the other copy.
git switch main
tag history
A permanent name for one commit, usually a version number.
🧒 A bookmark that never moves.
git tag -a v1.0 -m "First version"
three-way merge branching
A merge that compares both branch tips with their common ancestor to combine changes.
🧒 Compare both new versions with the old one.
git merge feature/todo
tracked file basics
A file Git already keeps history for.
🧒 Has a Git sticker: Git keeps its history.
git ls-files
untracked file basics
A new file Git does not keep history for yet.
🧒 A new paper without a Git sticker.
?? todo.txt
upstream remote
The remote branch your branch is linked to (set with push -u); git pull and git push use it.
🧒 Your locker shelf.
git push -u origin main
workflow workflow
The agreed way a team uses branches, pull requests and reviews.
🧒 The team’s rules of the game.
feature branch → pull request → merge
working folder basics
Your normal project folder with the files you edit (also called working tree or working directory).
🧒 Your desk.
ls