How to Learn Git for Beginners: Init, Add, Commit, Branch and Merge
Updated December 2026
Written by the Toolpuffin team. Tools in this guide are tested in the browser.
Git remembers the versions of your files, so you can change things without losing the old state. This guide explains the basic cycle in plain words: start a repository, stage changes, save them as a commit, and work on a branch. You can try every step in a practice terminal in your browser without touching your own files.
Try the tool: Learn Git and the Terminal
What Git does with your files
Git works with snapshots. In the Pro Git book, the git commit command takes all the file contents that were staged with git add and records a new permanent snapshot, then moves the branch pointer on the current branch up to it.
Source: Pro Git: Appendix C, Basic Snapshotting
The staging area is a step between your working folder and the saved history. The same appendix explains that git add adds content from the working directory into the staging area (also called the index) for the next commit, and that git commit by default only looks at this staging area. So git add is how you decide what the next snapshot will contain.
Start a repository
A repository is a folder that Git keeps track of. The Git documentation says that git init creates an empty Git repository, basically a .git directory, and that running it in an existing repository is safe: it does not overwrite what is already there.
Source: Git documentation: git init
The name of the first branch depends on the setup. The Pro Git book says that by default Git creates a branch called master, and that from Git 2.28 you can set a different name for the initial branch, for example main.
Source: Pro Git: First-Time Git Setup
The cycle: status, add, commit
Most of your time in Git is a small loop: change a file, look at the status, stage the change, commit it. In the Pro Git book, untracked files are files that were not in your last snapshot and are not in your staging area, and git add is how you start tracking them or stage a change. A file under Changes not staged for commit is a tracked file that was modified but not yet staged.
Source: Pro Git: Recording Changes to the Repository
- Change or create a file.
- Run git status to see what Git notices.
- Run git add with the file name to stage the change.
- Run git commit -m with a short message that says what changed.
- Run git log --oneline to see the history, newest first.
| Command | What it does |
|---|---|
| git init | Turns the folder you are in into a repository. |
| git status | Shows which files changed and which are staged. |
| git add notes.txt | Stages the file for the next commit. |
| git commit -m "message" | Saves the staged changes as a commit. |
| git log --oneline | Shows the history, one line per commit. |
Work on a branch and merge it
A branch is a separate line of work. The Git documentation says that git switch switches to a specified branch, updating the working tree and the index to match it, and that a new branch can be created with the option -c. In short, git switch -c idea makes a branch called idea and moves you onto it.
Source: Git documentation: git switch
When you merge a branch that is directly ahead of the one you are on, nothing needs to be combined. The Pro Git book describes that Git then simply moves the pointer forward, which it calls a fast-forward. The practice terminal in the course only does this simple kind of merge. Real Git can also merge two branches that both moved on, which is a next step.
Practise in your browser
The course has 8 short lessons that start with the terminal commands pwd, ls and cd and end with a branch and a merge. You type in a small practice terminal that runs in your browser, each lesson has a goal that is checked as you type, and your own files are never touched. It is a small copy of Git, so it does not know every command, such as push or pull.