SadServers
  • Scenarios
  • Labs
    All Labs Linux & Bash Web Servers Databases Data Processing Docker Kubernetes CI/CD Infrastructure as Code Tooling / Applications
  • Dashboard
  • Solutions
    For Individuals For Businesses
  • Ranking
  • Newsletter
  • Documentation
    FAQ Support Pro Accounts Pro+ Accounts Business Accounts Gift API CLI/TUI Privacy Troubleshooting Interviews
  • Blog
  • Pricing
  • Gift
    Gift Purchase Gift Redeem
  • About
Log In - Sign Up
  1. Labs
  2. Git
  3. Cheatsheet

Guide

Concepts and learning path

Troubleshooting

Failure modes and fixes

Cheatsheet

Commands to keep handy

Git cheatsheet

Setup and clone

CommandDescription
git config --global user.name "Name"Set commit author name
git config --global user.email "a@b.com"Set commit author email
git clone git@host:org/repo.gitClone via SSH
git clone --depth 1 urlShallow clone (CI)

Daily workflow

CommandDescription
git statusChanged and staged files
git add filegit add -pStage (patch = hunk by hunk)
git commit -m "msg"Create commit
git pull --rebaseFetch and rebase onto remote
git push origin branchPush branch to remote
git log --oneline -10Recent commits, one line each
git diffgit diff --stagedUnstaged vs staged diff

Branches

CommandDescription
git branchList local branches
git checkout -b feature/xCreate and switch branch
git switch mainSwitch branch (Git 2.23+)
git merge feature/xMerge branch into current
git branch -d feature/xDelete merged branch

Remotes

git remote -v git fetch origin git push -u origin main # set upstream tracking git remote add upstream URL git fetch upstream && git merge upstream/main

Undo and fix mistakes

CommandDescription
git restore fileDiscard working tree changes
git restore --staged fileUnstage file
git reset --soft HEAD~1Undo last commit, keep changes staged
git reset --hard HEAD~1Discard last commit and changes
git revert SHANew commit that undoes a commit (safe on shared branches)
git stashgit stash popTemporarily shelve changes

Inspect history

git show SHA git blame file git log --graph --oneline --all git reflog # recover "lost" commits

Tags

git tag v1.0.0 git tag -a v1.0.0 -m "Release" git push origin v1.0.0 git checkout tags/v1.0.0

Pro tips

  • git status before every commit — know what you are recording
  • Pull before push on shared branches to avoid non-fast-forward rejections
  • Use git revert on shared history; reserve reset --hard for local-only fixes
  • git reflog recovers commits after a mistaken reset
  • Large binaries belong in Git LFS or artifact storage, not plain Git

Practice scenarios

Hands-on Git scenarios on live Linux VMs: git

SadServersSadServers

Real-world Linux and DevOps scenarios for hands-on learning and technical assessment.

Uptime Robot ratio (30 days)
Product
  • Scenarios
  • For Individuals
  • For Businesses
  • Pricing
Resources
  • FAQ
  • Blog
  • Newsletter
Company
  • About Us
  • Support
  • Privacy Policy
  • Terms of Service
  • Contact
Connect With Us
info@sadservers.com

Made in Canada 🇨🇦
Updated: 2026-06-13 16:06 UTC – 2d2950a