The 20 Git commands you actually need

The Git commands for every day, from init and commit to branches, pull and push, plus the five ways back when something goes wrong, each linked to its moment in the video.

Short answer: for daily work you need status, add, commit, pull and push, plus switch and merge for branches. Learn restore, revert and reflog early too: they are how you get back from a mistake without losing work.

Git has more than a hundred commands, and tutorials tend to start with the rare ones. Fear of the command line usually comes from not knowing how to undo, so this list ends with the ways back.

The time in the last column jumps to the moment the video shows the command in a real terminal.

Nothing loads from YouTube until you press play. Then Google receives your IP address and may set its own storage. Narrated with an AI-generated voice. Privacy

Which commands start a project?

CommandWhat it doesVideo
git initTurns the current folder into a repository.0:20
git clone <url>Copies a repository, with its history, to your computer.0:29
git configSets your name and e-mail, once per computer with --global.0:37

Which commands save your work?

CommandWhat it doesVideo
git statusShows what changed and what is staged. Run it often.0:46
git add <file>Stages a change for the next commit.0:54
git commit -m "..."Saves the staged changes as one step in history.1:03
git log --onelineLists the commits, one per line.1:13
git diffShows the changes line by line.1:22

Which commands work with branches?

CommandWhat it doesVideo
git branchLists branches, or makes one with a name.1:31
git switch <branch>Moves to a branch; -c creates it first.1:37
git merge <branch>Brings another branch's commits into yours.1:47
git rebase <branch>Replays your commits on top of another branch for a straight history.1:56

Which commands share with a remote?

CommandWhat it doesVideo
git fetchDownloads new commits without changing your files.2:06
git pullFetches and merges into your branch in one go.2:15
git pushSends your commits to the remote.2:24

How do you undo a mistake in Git?

Pick by where the mistake is:

The mistakeCommandVideo
Unfinished work in the way, but you want to keep itgit stash, later git stash pop2:34
A file changed and you want the last committed version backgit restore <file>2:43
Commits on your own branch that should not be theregit reset <commit> (--hard also throws the changes away)2:53
A commit that is already pushed and sharedgit revert <commit>: a new commit that undoes it3:03
A commit you lost after a reset or rebasegit reflog: every place your branch has been, so you can go back3:14

The rule that saves the most trouble: never reset or rebase commits other people already pulled. Use revert there.

Where can you check this?

What comes after your first push?

Once your projects are on GitHub, your profile page is the first thing people see. Profile README Studio builds the README for it from 31 layouts and 45 block types, with a preview that looks the way GitHub shows it. How to make a GitHub profile README walks through the repository it lives in.

The tool

Do it in your browser.

GitHub

Profile README Studio

Build a GitHub profile README with a pixel-accurate preview, and badges, icons and cards the studio draws itself instead of outside servers.

Keep reading

More from the blog.

Every post