Git Tutorial for Beginners
Learn Git version control step by step, from your first commit to branching, merging, rebasing and recovering lost work, with real Git commands and their output.
Browse all 30 lessons by stage
- Lessons
- 30
- Code examples
- 71
- Exercises
- 110
- Quiz questions
- 120
Git course at a glance
Who it's for
Beginners who have never used version control, students handing in projects, developers who know a few Git commands but get stuck, and anyone starting a job on a software team.
Prerequisites
None. The lessons explain the few terminal commands you need, such as changing folders, as they come up.
What you need
Git installed on your computer (Git for Windows includes Git Bash), a terminal and a text editor. No account or internet connection is needed for most lessons.
How long it takes
About two weeks for the beginner and intermediate lessons at an hour a day, and another week or two for the advanced lessons and in-depth guides.
Git roadmap: beginner to advanced
Work through the 20 core chapters in the first three stages in order, then use the reference stages to go deeper. Each reference lesson links to its prerequisite and includes examples, practice and a quiz.
Beginner
Install Git, make commits, read history, manage files and set up Git the way you like it.
- 1IntroductionWhat version control is, why Git matters, how to install it and how to set your name and email.
- 2init, add & commitCreate a repository, stage changes with git add, save them with git commit and check progress with git status.
- 3log, diff & .gitignoreBrowse commits with git log, see exact changes with git diff and git show, and ignore files with .gitignore.
- 4Moving & Removing FilesRename, move and delete files the Git way, stop tracking files without deleting them, clear out untracked clutter with git clean, and handle line endings with .gitattributes.
- 5Config & AliasesUnderstand Git's configuration levels, choose your editor and line-ending settings, and save time with aliases.
Intermediate
Branches, merging, conflicts, undoing, stashing, remotes and tags: the commands you'll use every working day.
- 6BranchesWork on new ideas safely in branches, then switch between them, list them and clean them up.
- 7Merging & ConflictsBring a branch's work into main with git merge, understand fast-forward merges and fix merge conflicts.
- 8Merge ConflictsRead conflict markers with confidence, choose ours or theirs, use the three-way zdiff3 style and editor tools, resolve conflicts during a rebase, and prevent most conflicts before they happen.
- 9Undoing ChangesSafely undo mistakes at every stage: unstaged edits, staged files, the last commit and older commits.
- 10StashPark unfinished changes with git stash, list, apply and drop stashes, include untracked files and turn a stash into a branch.
Show all 7 lessonsShow fewer
Advanced
Rebase, cherry-pick, reflog, bisect, hooks, submodules, worktrees and team workflows: confident control over history.
- 13RebaseReplay your commits on top of another branch with rebase, compare it with merge, tidy commits with interactive rebase and follow the golden rule.
- 14Cherry-PickCopy specific commits from one branch to another with cherry-pick, pick ranges, handle conflicts and know when not to use it.
- 15Reflog & RecoveryUse the reflog to find and recover commits lost to a bad reset, a deleted branch or a rebase gone wrong.
- 16Bisect & BlameFind the exact commit that broke something with git bisect, and see who last changed each line with git blame.
- 17Git HooksRun scripts automatically at key moments with Git hooks: block bad commits with pre-commit, enforce message formats with commit-msg, run tests before pushing, and share hooks with your team.
Show all 8 lessonsShow fewer
- 18SubmodulesInclude one Git repository inside another with submodules: adding them, cloning a project that uses them, updating to newer versions, removing them, and when to use a package manager instead.
- 19WorktreesCheck out several branches at the same time in separate folders with git worktree, so you can fix a bug or review a pull request without stashing or disturbing your current work.
- 20Team WorkflowsCompare the main ways teams organise branches, from feature branches to trunk-based development and Git Flow, and adopt good daily habits.
Precision and repository data
Partial staging, HEAD and revision syntax, .gitattributes and line endings, Git LFS for large files, and signed commits and tags.
- 21Git Partial Staging and the IndexLearn git add -p, staged snapshots and partial commits with a reproducible lab, index inspection, practical exercises and clear answers.
- 22Git HEAD, Detached HEAD and Revision SyntaxUnderstand Git HEAD, detached HEAD, parent notation and commit ranges through a local lab, recovery exercises and practical reference questions.
- 23Git .gitattributes and Line Ending NormalizationUse .gitattributes for LF and CRLF policies, inspect indexed bytes, renormalize tracked text carefully and distinguish attributes from ignore rules.
- 24Git Large File Storage and Binary Asset WorkflowsLearn Git LFS pointers, tracking rules, clone behavior and object verification with a local lab, safe migration guidance and worked exercises.
- 25Sign and Verify Git Commits and TagsSign Git commits and annotated tags with SSH keys, configure allowed signers and understand what a valid signature proves about repository history.
Team tooling and recovery
Patches via format-patch/am, sparse checkout, partial clone, bundles, rerere for conflicts, and refspecs with force-with-lease.
- 26Git Patches with diff, apply, format-patch and amCreate Git patches, check them before applying and transfer commit series with format-patch and am while distinguishing file changes from commit metadata.
- 27Git Sparse Checkout and Partial CloneUse cone-mode sparse checkout to select working-tree directories and distinguish those path rules from partial-clone object filtering and lazy downloads.
- 28Git Bundle Files for Offline Transfer and RecoveryCreate and verify Git bundles, clone offline history and understand prerequisite commits, external assets and the limits of a repository recovery artifact.
- 29Reuse Git Conflict Resolutions with RerereEnable Git rerere, inspect reused conflict resolutions and keep index updates under review when a merge or rebase encounters a familiar conflict.
- 30Git Refspecs and Explicit Force-With-Lease ChecksRead Git fetch and push refspecs, distinguish tracking refs from branches and use an explicit force-with-lease expectation to detect unseen remote updates.
What is Git?
Git is a version control system: a tool that records snapshots of your project over time. Every time you reach a point worth keeping, you make a commit, and Git remembers exactly what every file looked like at that moment. You can look back at any snapshot, see what changed and why, and undo mistakes.
Git also lets you work on several ideas at once with branches, and combine work from many people without overwriting each other's changes. That's why almost every software team in the world uses it, from two-person startups to the developers of Linux and Windows.
This tutorial teaches Git in the terminal, one command at a time, in three stages. The beginner stage sets Git up, makes your first commits, reads the history, manages files and configures Git with handy aliases. The intermediate stage covers branches, merging and resolving conflicts, undoing changes safely, stashing unfinished work, connecting to remote repositories and tagging releases. The advanced stage teaches the tools professionals rely on: rebasing and interactive rebase, cherry-picking, recovering lost commits with the reflog, hunting bugs with bisect and blame, automating checks with hooks, including other repositories as submodules, working on several branches at once with worktrees, and choosing a workflow for a team.
Every lesson shows each command together with the output Git prints, so you know what to expect before you try it yourself. Git runs on your own computer; to share your repositories online and collaborate, follow on with the GitHub tutorial.
How to follow this course
Work through the 20 core lessons in order, because each one builds on the last. After that, the in-depth guides cover the situations teams run into. The precision and repository data guides cover staging part of a file, HEAD and revision syntax, .gitattributes and line endings, Git LFS for large files, and signing commits and tags. The team tooling and recovery guides cover patches, sparse checkout and partial clone, bundles for offline backups, reusing conflict resolutions with rerere, and refspecs with safe force pushes. Each guide lists the core lessons to finish first.
What you will learn
11 practical skills, built one lesson at a time
- Explain what version control is and why every developer uses it
- Install and configure Git, and speed up daily work with aliases
- Save work with add and commit, and read history with log, diff and show
- Rename, move and untrack files, and keep the working folder clean
- Create, switch and merge branches, and resolve merge conflicts confidently
- Undo changes safely with restore, revert, reset and stash
- Push, pull and fetch with remote repositories, and tag releases
- Rebase branches and tidy commits with interactive rebase
- Recover lost work with the reflog and find bugs with bisect and blame
- Automate checks with hooks, and use submodules and worktrees
- Choose and follow a team workflow such as feature branches or trunk-based development
Practise Git your way
Learning sticks when you use it. Pick a mode.
Git Exercises
Fill in blanks, predict output and fix broken code with instant feedback.
110 exercisesGit Quiz
5, 10 or 20 questions with a timer and explanations after every answer.
120 questionsGit Cheat Sheet
Every important piece of syntax on one printable page.
Open cheat sheetLearning Paths
See where Git fits in a complete roadmap, and what to learn next.
View learning pathsGit FAQ
What's the difference between Git and GitHub?
Git is the tool that tracks changes, and it runs on your computer without an internet connection. GitHub is a website that hosts Git repositories online so you can back them up, share them and collaborate. You can use Git without GitHub, but GitHub is built on Git. See the GitHub tutorial for the online side.
Do I need to use the command line?
Editors such as VS Code and apps like GitHub Desktop have buttons for common Git actions. Learning the commands first is still worth it: you'll understand what the buttons do, and you can follow any guide or fix problems when the buttons aren't enough.
How long does it take to learn Git?
The beginner and intermediate lessons, which cover the commands most developers use every day, can be learned in a week or two of short sessions. The advanced lessons are best learned gradually, as you meet situations like messy history or a mysterious bug that need them.
Should I use merge or rebase?
Both are correct. Merge keeps the exact history and is always safe on shared branches. Rebase gives a cleaner, straight history but rewrites commits, so use it only on your own branches. The rebase lesson compares them side by side.
Can I lose work with Git?
Committed work is very hard to lose: even after a hard reset or a deleted branch, the reflog can usually bring it back. Changes you never committed are the real risk, which is why committing small and often is the best habit to build.
Is Git only for code?
No. Git works with any text files, so writers use it for books, scientists for data analysis scripts and designers for website content. It's less suited to big binary files like videos.
Is this Git course free?
Yes. All 20 core lessons, the 10 in-depth guides, the exercises, the quiz and the cheat sheet are free, with no account or sign-up needed.
Which Git version does the course use?
The output in the lessons comes from recent Git 2.x releases, and any current version prints the same or very similar text. Commands such as git switch and git restore need Git 2.23 or later, so update an older installation before you start.
What are the most important Git commands to learn first?
Start with git init, git status, git add, git commit, git log and git diff, then git switch, git merge, git pull and git push. The beginner and intermediate lessons cover exactly these, in that order.
Can I use Git with a graphical app instead of the terminal?
Yes. VS Code, GitHub Desktop and many other apps provide buttons for common Git tasks. Learning the commands first helps you understand what those buttons do and fix problems when an app gets stuck.
More tutorials
SQL
The language for asking databases questions and keeping data organised.
Start SQLMongoDB
The popular document database for flexible, JSON-like data at any scale.
Start MongoDBGitHub
Host your code online, collaborate with others and publish websites.
Start GitHubHTML
The skeleton of every web page. Start here.
Start HTMLCSS
Colours, fonts, spacing and layouts that make pages beautiful.
Start CSSJavaScript
The programming language that makes web pages interactive.
Start JavaScript