Dev In The Mountain Header
A Developer In The mountains having fun

Git Cheat Sheet

A quick reference for common Git commands.

Basic Commands

Setup

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

Creating Repositories

git init                  # Initialize a new Git repository
git clone <url>           # Clone a remote repository

Basic Workflow

git status                # Check status of working directory
git add <file>            # Stage a file
git add .                 # Stage all changes
git commit -m "message"   # Commit staged changes
git push                  # Push to remote repository
git pull                  # Pull from remote repository

Branching

git branch                # List branches
git branch <name>         # Create new branch
git checkout <name>       # Switch to branch
git checkout -b <name>    # Create and switch to new branch
git merge <branch>        # Merge branch into current branch
git branch -d <name>      # Delete branch

Viewing History

git log                   # View commit history
git log --oneline         # Condensed log view
git diff                  # Show unstaged changes
git diff --staged         # Show staged changes

Undoing Changes

git restore <file>        # Discard changes in working directory
git restore --staged <file> # Unstage a file
git reset HEAD~1          # Undo last commit (keep changes)
git reset --hard HEAD~1   # Undo last commit (discard changes)

Remote Repositories

git remote -v             # List remote repositories
git remote add <name> <url>  # Add remote repository
git fetch                 # Download remote changes
git push -u origin <branch>  # Push branch to remote

Useful Commands

git stash                 # Temporarily save changes
git stash pop             # Restore stashed changes
git tag <name>            # Create a tag
git show <commit>         # Show commit details

For more advanced Git topics, see the Git Worktrees article.

More places to find me
Mental Health
follow me on Mastodon