#1 India's Top IT Training Institute

×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
🌿 FREE · 28 COMMANDS

Git Commands Cheat Sheet: From First Commit to Fixing Mistakes

The Git commands you need most, with a warning on the ones that rewrite history.

  • ✍️ Everyday workflow
  • ↩️ Undo safely
  • 🔍 Inspect and debug

How to use the Git Commands Cheat Sheet

  1. 1. Search a taskType undo, stash or branch to find the right command.
  2. 2. Read the warningCards say when a command rewrites history or deletes work.
  3. 3. DownloadKeep your filtered list as a text file.

The everyday loop

Most work is a short loop: git status to see what changed, git add -p to stage the parts you mean, git commit -m "Add login form" to save them, and git push. Start new work on a branch with git switch -c feature/login, which is the modern replacement for checkout -b. Before you open a pull request, git pull --rebase keeps your commits on top of the latest main.

Write commit messages in the imperative, as if completing the sentence If applied, this commit will…: Add, Fix, Update, Remove.

Undoing things, from safest to riskiest

  • git restore file throws away unstaged edits to one file.
  • git restore --staged file unstages but keeps the edit.
  • git commit --amend fixes the last commit before you push.
  • git revert <commit> adds a new commit that undoes an old one, safe on shared branches.
  • git reset --hard HEAD~1 moves the branch back and deletes changes. Use with care.

If something disappears, git reflog lists every place HEAD has been, so you can usually get committed work back. git clean -fd deletes untracked files for good; preview first with -n. See how branches and merges look as a picture in the Git branching visualizer, and set up ignore rules with the .gitignore generator.

Frequently asked questions

Should I use git switch or git checkout?

Both work. switch and restore were added in Git 2.23 to split checkout's two jobs, so they are clearer for beginners.

When should I rebase instead of merge?

Rebase your own local or private branch to keep history straight. Merge shared branches, because rebasing rewrites commits others may have.

Is the Git Commands Cheat Sheet free?

Yes, the Git Commands Cheat Sheet is free. The first time you download your first cheat sheet, you are asked for your name and WhatsApp number once. After that, this and every other Uncodemy tool opens straight away without the form.

More free tools

See all free tools