Quick reference for common Git commands.

Setup

git config --global user.name "Your Name"
git config --global user.email "your@email.com"

Basic Workflow

git init                    # Initialize repo
git add .                   # Stage changes
git commit -m "message"     # Commit
git push origin main        # Push to remote

Branching

git branch feature-name     # Create branch
git checkout feature-name   # Switch branch
git checkout -b feature-name # Create and switch
git merge feature-name      # Merge branch

Undoing Changes

git restore file.txt        # Discard changes
git reset HEAD~1            # Undo last commit
git revert commit-hash      # Create reverse commit

See also: DevOps Guide