← Back to Mission Control

Quick Command Reference

3 min read

Git Commands Cheat Sheet

Mission Phase 33 • Reference Material

Essential Commands

Setup & Configuration

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

Creating Repositories

git init
git clone <url>

Basic Workflow

git status
git add <file>
git add .
git commit -m "message"
git push
git pull

Branching

git branch                    # List branches
git branch <name>             # Create branch
git switch <branch>           # Switch branch
git switch -c <branch>        # Create and switch
git branch -d <branch>        # Delete branch
git merge <branch>            # Merge branch

Viewing History

git log
git log --oneline
git log --graph --all
git diff
git diff --staged
git show <commit>

Undoing Changes

git restore <file>            # Discard changes
git restore --staged <file>   # Unstage
git commit --amend            # Amend last commit
git revert <commit>           # Revert commit
git reset --soft HEAD~1       # Undo commit, keep changes staged
git reset HEAD~1              # Undo commit, unstage changes
git reset --hard HEAD~1       # Undo commit, discard changes

Stashing

git stash
git stash save "message"
git stash list
git stash apply
git stash pop
git stash drop

Remote Repositories

git remote -v
git remote add origin <url>
git push -u origin main
git push origin <branch>
git pull origin <branch>
git fetch

Rebasing

git rebase <branch>
git rebase -i HEAD~3
git rebase --continue
git rebase --abort

Tagging

git tag
git tag v1.0.0
git tag -a v1.0.0 -m "Version 1.0"
git push --tags

Inspection

git blame <file>
git log --follow <file>
git reflog

GitHub CLI

gh auth login
gh repo create
gh pr create
gh pr list
gh pr view <number>
gh issue create
gh issue list

Special Files

.gitignore

# Patterns to ignore
*.log
node_modules/
.env
build/

Useful Aliases

git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.unstage "restore --staged"
git config --global alias.lg "log --graph --oneline --all"

Common Workflows

Feature Development

git switch main
git pull
git switch -c feature-name
# Make changes
git add .
git commit -m "Add feature"
git push -u origin feature-name
# Create PR on GitHub
# After merge:
git switch main
git pull
git branch -d feature-name

Fixing Bugs

git switch main
git switch -c bugfix-name
# Fix bug
git add .
git commit -m "Fix bug"
git push -u origin bugfix-name

Updating Fork

git remote add upstream <original-repo-url>
git fetch upstream
git switch main
git merge upstream/main
git push origin main

Pro Tips

  • Run git status frequently
  • Commit often with clear messages
  • Pull before starting work
  • Never force push to shared branches
  • Use branches for all work

Next: Mission Complete

You now have a complete command reference. Bookmark this page! Next, we'll wrap up your training and discuss your journey ahead.