Git Cheat Sheet

Printable reference for common Git commands

🚀 Getting Started

Initial Setup

Configure user git config --global user.name "Your Name"
Configure email git config --global user.email "email@example.com"
Initialize repository git init
Clone repository git clone repository-url

Basic Workflow

Check status git status
Add files git add filename
Add all files git add .
Commit changes git commit -m "message"

đŸŒŋ Working with Branches

Branch Management

List branches git branch
Create branch git branch branch-name
Switch branch git checkout branch-name
Create & switch git checkout -b branch-name
Delete branch git branch -d branch-name

Merging

Merge branch git merge branch-name
Abort merge git merge --abort
View merge conflicts git status

🌐 Remote Operations

Remote Management

Add remote git remote add origin url
List remotes git remote -v
Remove remote git remote remove origin

Push & Pull

Push to remote git push origin branch-name
Pull from remote git pull origin branch-name
Fetch changes git fetch origin

📜 Viewing History

Log & History

View commit history git log
One-line log git log --oneline
Graph view git log --graph
Show changes git show commit-hash

Comparing Changes

Show differences git diff
Staged changes git diff --staged
Between commits git diff commit1..commit2
Between branches git diff branch1..branch2

â†Šī¸ Undoing Changes

Before Committing

Unstage file git reset HEAD filename
Discard changes git checkout -- filename
Discard all git reset --hard HEAD

After Committing

Revert commit git revert commit-hash
Reset to commit git reset --hard commit-hash
Amend last commit git commit --amend

đŸˇī¸ Tags & Releases

Tag Management

Create tag git tag v1.0.0
Annotated tag git tag -a v1.0.0 -m "message"
List tags git tag
Push tags git push --tags

Working with Tags

Checkout tag git checkout v1.0.0
Delete tag git tag -d v1.0.0
Show tag info git show v1.0.0

⚡ Useful Aliases

Add these to your ~/.gitconfig file for faster workflow:

Common Aliases

Status shortcut git st
Add all shortcut git aa
Commit shortcut git cm
Checkout shortcut git co

Advanced Aliases

Pretty log git lg
Unstage all git unstage
Last commit git last

đŸŽ¯ Quick Reference

Daily Workflow

  1. 1. git status
  2. 2. git add .
  3. 3. git commit -m "message"
  4. 4. git push

New Feature

  1. 1. git checkout -b feature-name
  2. 2. Make changes
  3. 3. git add . && git commit
  4. 4. git push -u origin feature-name

Emergency Fix

  1. 1. git checkout -b hotfix
  2. 2. Fix the issue
  3. 3. git add . && git commit
  4. 4. git checkout main && git merge hotfix

This cheat sheet is part of the Git & GitHub Mastery learning experience.

For more detailed explanations and interactive exercises, visit the full course.