30 lessons

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.

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
30 lessons71 examples110 exercises

Practise Git your way

Learning sticks when you use it. Pick a mode.

Git 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