Setup
git config --global user.name "Your Name"
git config --global user.email "your@email.com"
Starting a Repo
git init # Initialize new repo
git clone <url> # Clone existing repo
Daily Workflow
git status # Check status
git add <file> # Stage file
git add . # Stage all changes
git commit -m "message" # Commit staged changes
git push # Push to remote
git pull # Fetch and merge from remote
Branches
git branch # List branches
git branch <name> # Create branch
git checkout <branch> # Switch branch
git checkout -b <name> # Create and switch
git merge <branch> # Merge branch into current
git branch -d <name> # Delete branch
Viewing History
git log # Show commit history
git log --oneline # Compact history
git diff # Show unstaged changes
git diff --staged # Show staged changes
Undoing Things
git checkout -- <file> # Discard changes in file
git reset HEAD <file> # Unstage file
git reset --soft HEAD~1 # Undo last commit (keep changes)
git reset --hard HEAD~1 # Undo last commit (discard changes)