Level 1 — Beginner: the foundations of Git
Git is a version control system. In practice, it records every change to your code in a history, like save points in a video game. If you break something, you can go back. If you work as a team, everyone can modify the code without overwriting each other's work. Here are the five commands to get started.
git init — Create a repository
Every Git project starts with git init. This command creates a hidden .git/ folder that contains your project's entire history. You never touch this folder directly — Git handles it.
git add — The staging area
Before saving, you need to tell Git which files to include. That's the role of the staging area. Think of it as a shopping cart: you place what you want to buy before going to the checkout. git add places a file in that cart.
git commit — Save a snapshot
git commit takes everything in the staging area and creates a permanent snapshot. Each commit has a unique identifier (a hash like a1b2c3d) and a descriptive message. It's your save point.
git status — Read the project state
This is the command you'll use most often. git status shows you which files have been modified, which are in the staging area, and which are not yet tracked by Git. When in doubt, run git status.
git log — Navigate the history
git log displays the list of commits from most recent to oldest. With the --oneline option, you get a compact view perfect for quickly spotting a commit. It's your logbook.
Mastered the five basic commands? Great. Let's move on to branches — that's where Git becomes truly powerful.
Level 2 — Intermediate: branches and collaboration
Branches let you work on multiple features in parallel without stepping on each other's toes. Think of a tree: the trunk is your main branch, and each branch is a feature being developed. When it's ready, you merge it back into the trunk.
git branch / git switch — Create and navigate
git branch name creates a new branch. git switch name moves you onto it (you may also see the older syntax git checkout, but switch is clearer). Each branch is an isolated workspace.
git merge — Merge a branch
When your feature is complete, you go back to main and merge your branch with git merge. If nobody has modified the same files, Git does a fast-forward merge — it's automatic and clean.
Merge conflicts: understanding and resolving
When two branches modify the same line of the same file, Git can't guess which version to keep. It flags a conflict. Don't panic: Git marks the conflicting areas in the file with <<<<<<< and >>>>>>> markers. You choose the right version, remove the markers, then do an add + commit.
git push / git pull — Sync with a remote
git push sends your commits to a remote server (GitHub, GitLab...). git pull fetches other people's commits and merges them into your branch. It's the basic duo of collaboration.
git clone — Get an existing project
git clone copies a remote repository to your machine, along with its entire history. It's the first command you run when joining an existing project.
You know how to create branches, merge and collaborate? You already have an operational skill level for working in a team. To go further, here are the pro tools.
Level 3 — Advanced: the pro toolkit
These commands aren't essential every day, but they'll get you out of tricky situations and save you valuable time. It's what separates someone who uses Git from someone who masters it.
git rebase — Rewrite history
git rebase takes the commits from your branch and replays them on top of another branch. The result: a linear history with no merge commits. It's cleaner, but should only be used on branches you haven't shared yet (push).
git stash — Set aside temporarily
Working on a feature but need to switch branches urgently? git stash puts your changes aside in a temporary stack. You switch branches, do what you need to do, then git stash pop restores your work.
git cherry-pick — Copy a specific commit
Need to grab a single commit from another branch without merging everything? git cherry-pick copies that exact commit into your current branch. Ideal for applying a targeted fix.
git reflog — The safety net
Did an overly aggressive reset and think you lost commits? git reflog records everything Git has done, even destructive operations. You can find any previous state and go back to it. It's Git's ultimate Ctrl+Z.
git reset / git revert — Undo changes
Two approaches to undo. git reset moves the branch pointer backwards — commits disappear from history (use --soft to keep the files). git revert creates a new commit that undoes the changes — history stays intact. When working in a team, prefer revert.
git bisect — Find the faulty commit
A bug appeared but you don't know when? git bisect does a binary search through your history. You give it a "good" commit and a "bad" commit, and Git has you test the middle commit. In a few steps, you find exactly the commit that introduced the bug.
There you have it — a complete overview of essential Git commands, from beginner to advanced level. The key to improving: practice regularly. Create a test project and experiment with each command.