15 Essential Git Commands (Cheat Sheet)
The 15 Git commands you will use almost every day, each with a one-line purpose and an example, plus a daily workflow and common mistakes.
Short answer: these are the 15 essential Git commands you will use almost every day: config, init, clone, status, add, commit, diff, log, switch, merge, pull, push, restore, stash and revert. Learn these and you can handle most solo and team work. Each has a one-line purpose below.
Setup and Starting
1. git config
Set your name and email once; every commit records them.
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
2. git init
Turn the current folder into a new Git repository.
git init
3. git clone
Copy an existing repository, with its full history, to your computer.
git clone https://github.com/example/project.git
Saving Your Work
4. git status
Show which files are changed, staged or untracked. Run it often.
git status
5. git add
Stage changes: choose what goes into the next commit.
git add app.py # one file
git add . # everything in this folder
6. git commit
Save the staged changes as a snapshot with a message. Write what and why, briefly.
git commit -m "Add input validation to signup form"
7. git diff
See exactly what changed. Plain git diff shows unstaged changes; add --staged for what is about to be committed.
git diff
git diff --staged
8. git log
Browse the history of commits. The short form is easiest to read.
git log --oneline
Branches and Merging
9. git switch
Move between branches. With -c it creates a new branch first. (Older tutorials use git checkout for this.) Use git branch to list branches.
git switch -c login-page # create and move to a new branch
git switch main # go back
10. git merge
Bring another branch's work into the branch you are on.
git switch main
git merge login-page
If two branches changed the same lines, Git stops and asks you to resolve the conflict.
Working With a Remote (GitHub)
11. git pull
Download new commits from the remote and update your branch. Do this before you start work.
git pull
12. git push
Upload your commits to the remote.
git push origin login-page
Undoing and Pausing
13. git restore
Throw away uncommitted changes in a file, or unstage it. Careful: discarding changes cannot be undone.
git restore app.py # discard changes in the file
git restore --staged app.py # unstage, keep the changes
14. git stash
Put unfinished changes aside so you can switch tasks, then bring them back.
git stash
git stash pop
15. git revert
Undo a commit that is already shared by adding a new commit that reverses it. It is safe because it does not rewrite history.
git revert a1b2c3d
A Daily Workflow in Six Lines
git pull
git switch -c fix-typo
# ...edit files...
git add .
git commit -m "Fix typo in README"
git push origin fix-typo
Then open a pull request on GitHub. The difference between Git and GitHub is explained in Git vs GitHub.
Common Mistakes
Committing secrets such as API keys. Keep them out with a
.gitignorefile.Vague messages like "update" or "fix". Future you will not know what changed.
Using
git add .without checkinggit status, so unwanted files get committed.Using
reset --hardas a first resort. It deletes work; tryrestoreorrevertfirst.
Practise these step by step in the tutorials Commits, History and Diffs, Branches, Merging and Merge Conflicts and Undoing Mistakes.
Key Takeaway
Status, add, commit, push and pull cover most days; branches, restore, stash and revert rescue you when plans change. Practise on a throwaway repository until the commands feel automatic.
Ready to start? Learn Git hands-on, along with APIs and backend basics, through a project you publish to GitHub. Begin with the free course Git, APIs and Backend for AI: Beginner.
Related articles
More in APIs and Backend
How to Keep API Keys Safe: .env Files and Secrets
Keep API keys out of your code: use .env files and environment variables, ignore them in Git, and know exactly what to do if a key leaks.
4 min readNov 14, 2026Frontend vs Backend: What's the Difference?
What the frontend and backend of an app are, how they differ, how they talk to each other and why AI calls and secret keys belong on the backend.
3 min readNov 12, 2026HTTP Status Codes Explained: 200, 404, 500 and More
What HTTP status codes mean, from 200 and 404 to 500, how the five groups work and how your code should react to each.
4 min readNov 9, 2026What Is JSON and Why Do APIs and AI Use It?
JSON is a simple text format for structured data. See what it looks like, its data types, how to read it in Python, and why APIs and AI apps depend on it.
3 min readNov 6, 2026REST API Methods Explained: GET, POST, PUT, PATCH, DELETE
What each REST API method does, with a to-do list example, typical status codes, PUT vs PATCH, and what safe and idempotent mean.
4 min readNov 4, 2026What Are Git and GitHub? The Difference Explained
Git tracks your code's history on your computer; GitHub hosts it online for sharing and teamwork. Learn the difference, the key terms and your first commands.
4 min readNov 2, 2026
Comments
Sign in to join the discussion.

