Git Cheat Sheet

All essential Git commands in one place

What is Git?

Git is a version control system used to track changes in code and collaborate with other developers. This cheat sheet provides the most commonly used Git commands for beginners and professionals.

Repository Setup

git init
git clone https://github.com/user/repo.git

Basic Workflow

git status
git add file.txt
git add .
git commit -m "Message"

Branching

git branch
git branch feature
git switch feature
git checkout main

Merging

git merge feature

Remote Repositories

git remote -v
git remote add origin URL
git push -u origin main
git pull origin main
git fetch origin

Undo Changes

git reset file.txt
git reset --soft HEAD~1
git revert commit_id

Stashing

git stash
git stash pop

Logs and History

git log
git log --oneline
git diff

.gitignore Example

node_modules/
*.log
.env

Common Workflow

git add .
git commit -m "Update"
git push

Pro Tips

  • Write clear commit messages
  • Use branches for features
  • Pull before pushing
  • Use .gitignore properly
  • Commit often

Related Tutorials

Git Tutorial | Git Commit | Git Branch | Git Merge