GIT COMMANDS QUICK REFERENCE
===========================
=== SETUP & CONFIG ===
git config --global user.name "Your Name"
git config --global user.email "email@example.com"
git config --list # View all settings
git init # Initialize new repository
git clone <url> # Clone remote repository
=== BASIC WORKFLOW ===
git status # Check repository status
git add <file> # Stage specific file
git add . # Stage all changes
git add -A # Stage all changes (including deletions)
git commit -m "message" # Commit with message
git push # Push to remote repository
git pull # Pull latest changes
=== BRANCHING ===
git branch # List all branches
git branch <name> # Create new branch
git checkout <branch> # Switch to branch
git checkout -b <name> # Create and switch to branch
git merge <branch> # Merge branch into current
git branch -d <name> # Delete branch (safe)
git branch -D <name> # Force delete branch
=== REMOTE REPOSITORIES ===
git remote -v # List remotes
git remote add origin <url> # Add remote origin
git remote remove <name> # Remove remote
git push -u origin <branch> # Push and set upstream
git fetch # Download objects from remote
git pull origin <branch> # Pull specific branch
=== VIEWING HISTORY ===
git log # View commit history
git log --oneline # Compact log format
git log --graph # Show branch graph
git show <commit> # Show commit details
git diff # Show unstaged changes
git diff --staged # Show staged changes
git diff <commit1> <commit2> # Compare commits
=== UNDOING CHANGES ===
git checkout -- <file> # Discard changes in file
git reset <file> # Unstage file
git reset --soft HEAD~1 # Undo last commit (keep changes)
git reset --hard HEAD~1 # Undo last commit (discard changes)
git revert <commit> # Create new commit that undoes changes
git clean -f # Remove untracked files
git clean -fd # Remove untracked files and directories
=== STASHING ===
git stash # Stash current changes
git stash pop # Apply and remove latest stash
git stash list # List all stashes
git stash apply stash@{0} # Apply specific stash
git stash drop stash@{0} # Delete specific stash
git stash clear # Delete all stashes
=== TAGGING ===
git tag # List all tags
git tag <tagname> # Create lightweight tag
git tag -a <tagname> -m "message" # Create annotated tag
git push origin <tagname> # Push tag to remote
git push origin --tags # Push all tags
=== ADVANCED OPERATIONS ===
git rebase <branch> # Rebase current branch
git rebase -i HEAD~3 # Interactive rebase (last 3 commits)
git cherry-pick <commit> # Apply specific commit
git bisect start # Start binary search for bugs
git blame <file> # Show who changed each line
git reflog # Show reference log
=== USEFUL FLAGS ===
-v, --verbose # More detailed output
-q, --quiet # Suppress output
--dry-run # Show what would happen
-f, --force # Force operation
-u, --set-upstream # Set tracking branch
=== GITIGNORE PATTERNS ===
*.log # Ignore all .log files
/temp # Ignore temp directory in root
build/ # Ignore build directory anywhere
!important.log # Don't ignore this specific file
*.tmp # Ignore all .tmp files
node_modules/ # Common: ignore Node.js modules
.env # Ignore environment files
*.pyc # Ignore Python compiled files
=== COMMON WORKFLOWS ===
# Start new feature
git checkout -b feature/new-feature
git add .
git commit -m "Add new feature"
git push -u origin feature/new-feature
# Merge feature branch
git checkout main
git pull origin main
git merge feature/new-feature
git push origin main
git branch -d feature/new-feature
# Fix merge conflicts
git status # See conflicted files
# Edit files to resolve conflicts
git add <resolved-files>
git commit -m "Resolve merge conflicts"
=== HELPFUL ALIASES ===
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.unstage 'reset HEAD --'
git config --global alias.last 'log -1 HEAD'