Git Tutorial
This Git tutorial teaches you version control from your very first commit to branching, merging, rebasing and team workflows on GitHub and GitLab. Git is a free, open-source distributed version control system that records every change to your files, so you can review history, undo mistakes and work with others safely.
Git was created in 2005 by Linus Torvalds to manage the Linux kernel, and today it is the standard tool for almost every software project.
What is Version Control?
Without version control, people save copies like report-final.doc, report-final-2.doc and report-really-final.doc. Version control replaces this with a timeline of snapshots, called commits. Each commit records what changed, who changed it, when, and why.
You can jump back to any snapshot, compare versions, and see exactly which change introduced a bug.
Why Learn Git?
- Every development job expects it — it is as basic as a code editor.
- Undo mistakes with confidence, even days later.
- Branches let you try ideas without breaking working code.
- Teams work on the same project at once and merge their changes.
- Deployment platforms like Vercel, Netlify and many CI tools deploy straight from Git.
Git vs GitHub
Git is the tool that runs on your computer and tracks changes. GitHub, GitLab and Bitbucket are websites that host Git repositories online and add collaboration features such as pull requests, issues, code review and CI/CD. You can use Git completely offline; the hosting sites are where you share your work.
Your First Git Commands
Here is a taste of a typical workflow. Each command is explained in the following chapters.
git init # start tracking a folder
git add index.html # stage a file
git commit -m "Add homepage" # save a snapshot
git log --oneline # view historyInitialized empty Git repository in /home/naeem/site/.git/ [main (root-commit) 4f2a9c1] Add homepage 1 file changed, 12 insertions(+) create mode 100644 index.html 4f2a9c1 (HEAD -> main) Add homepage
What This Git Tutorial Covers
- Installing and configuring Git
- The working directory, staging area and commits
- Viewing history, ignoring files and undoing changes
- Branches, merging, merge conflicts and rebasing
- Remotes, push, pull and fetch
- GitHub/GitLab workflow with pull requests, plus stash and tags
Frequently asked questions
Is Git the same as GitHub?
No. Git is the version control software on your machine. GitHub is an online service that hosts Git repositories and adds collaboration tools.
Is Git hard to learn?
The daily commands — add, commit, push, pull and branch — can be learned in an afternoon. Advanced topics like rebasing take more practice, but you can be productive quickly.
Is Git only for programmers?
No. Writers, designers and data scientists use Git for any text-based files such as documents, configuration or notebooks. It is less useful for large binary files.
Is Git free?
Yes. Git is open source and free to use. GitHub and GitLab also offer free plans with unlimited public and private repositories.