Learn Git: 24 free interactive lessons
3 to 5 minute lessons with a real Git terminal in your browser: commits, branches, merges and conflicts, remotes, reset, revert and rebase. Every lesson ends with a mission you solve with real commands.
Do it in the browser: a real Git tool, a short mission and instant feedback. No install. Optional certificate at the end of the course.
Open the courseLessons
- Your first repositoryGit keeps the history of a project folder: every saved version, who made it and when. A folder becomes a Git repository with one command,…
- The staging areaBefore saving a version, you choose what goes into it. git add copies a file into the staging area (also called the index): the draft of…
- Your first commitA commit is a saved snapshot of everything in the staging area, with a message, an author and a date. It is the unit of history in Git.
- Reading the historyEach commit remembers its parent, so the commits form a chain: the history. git log walks it from the newest commit back to the first.
- What changed? git diffBefore you commit, look at what you changed. git diff compares versions line by line, so you can commit related changes together.
- Undo changes in a fileBroke a file and want the last saved version back? git restore replaces your copy with the one Git has saved.
- Take a file out of the staging areaStaged something by mistake? You can take it out of the staging area without losing anything: the file stays in your folder exactly as it…
- Ignore files with .gitignoreSome files should never be committed: logs, build output, downloaded libraries. List them in a .gitignore file and Git stops offering them.
- Branches are pointersA branch lets you work on something new without touching the main line. In Git it is just a label that points at a commit, so creating one…
- HEAD and moving through historyHEAD marks where you are. Usually it points at a branch, but you can also point it at any old commit to look at the project as it was.
- Merging: fast-forwardWhen a branch is ready, you merge it into main. If main hasn't moved since the branch started, Git just slides main forward: a fast-forward.
- Three-way mergesIf both branches got new commits, Git can't just slide one forward. It compares both tips with their common ancestor and creates a merge…
- Resolving a merge conflictWhen both branches changed the same lines, Git can't choose for you. It stops the merge, marks the conflict in the file and waits for you…
- Pick a side: --ours and --theirsSometimes one side of a conflict is simply right. Instead of editing by hand, take that whole version of the file.
- Stash: put work asideHalfway through something and an urgent fix comes in? git stash puts your unfinished changes aside, leaves the folder clean, and gives…
- Tags for releasesA tag is a permanent name for a commit, usually a version number such as v1.0. Unlike a branch, it never moves.
- Publish your work: pushA remote is another copy of the repository, usually on a server such as GitHub or GitLab. git push sends your commits there so others can…
- Get updates: fetch and pullYour teammates push to the same server. To work on top of their changes, bring them into your copy.
- When a push is rejectedIf someone pushed while you were working, the server refuses your push: accepting it would erase their commits. Integrate their work first.
- Feature branches and pull requestsTeams rarely push straight to main. Each change goes on its own branch, which is pushed and reviewed in a pull request before it is merged.
- Fix the last commit: --amendTypo in the message, or a file left out? git commit --amend replaces the last commit with a corrected one.
- reset: move a branch backgit reset moves the current branch to another commit. The commits after it leave the branch, and the options decide what happens to your…
- revert: undo a published commitOnce a commit is on the server, don't rewrite history. git revert creates a new commit that does the exact opposite of the old one.
- Rebase and cherry-pickA merge keeps both lines of history. A rebase instead replays your commits on top of another branch, as if you had started from there: the…