AI Generate Git docs instantly

Git Cheat Sheet

Quick reference guide with copy-paste ready code snippets

Try DocuWriter Free

Setup & Config

7 snippets

Initial configuration

Set Username

git config --global user.name "Your Name"

Set Email

git config --global user.email "you@example.com"

Set Default Editor

git config --global core.editor "code --wait"

Set Default Branch

git config --global init.defaultBranch main

View Config

git config --list

Initialize Repo

git init

Clone Repo

git clone https://github.com/user/repo.git
git clone git@github.com:user/repo.git

Basic Commands

6 snippets

Everyday operations

Check Status

git status

Stage Files

git add file.txt        # Single file
git add .               # All changes
git add -p              # Interactive

Commit

git commit -m "message"
git commit -am "message"  # Add + commit tracked

View Log

git log
git log --oneline
git log --graph --oneline --all

Show Diff

git diff                # Unstaged changes
git diff --staged       # Staged changes
git diff HEAD~1         # Last commit

Remove File

git rm file.txt         # Delete and stage
git rm --cached file.txt  # Untrack but keep

Branches

6 snippets

Create and manage branches

List Branches

git branch              # Local
git branch -r           # Remote
git branch -a           # All

Create Branch

git branch feature-x
git checkout -b feature-x  # Create and switch

Switch Branch

git checkout main
git switch main         # Git 2.23+

Rename Branch

git branch -m old-name new-name
git branch -m new-name  # Current branch

Delete Branch

git branch -d feature-x   # Safe delete
git branch -D feature-x   # Force delete

Merge Branch

git checkout main
git merge feature-x

Tired of looking up syntax?

DocuWriter.ai generates documentation and explains code using AI.

Try Free

Remote Operations

6 snippets

Work with remote repositories

Add Remote

git remote add origin https://github.com/user/repo.git

View Remotes

git remote -v

Fetch

git fetch origin        # Get remote changes
git fetch --all         # All remotes

Pull

git pull                # Fetch + merge
git pull --rebase       # Fetch + rebase

Push

git push origin main
git push -u origin main  # Set upstream
git push --force        # Force (careful!)

Delete Remote Branch

git push origin --delete feature-x

Undo & Reset

6 snippets

Revert and fix mistakes

Unstage File

git restore --staged file.txt
git reset HEAD file.txt  # Older syntax

Discard Changes

git restore file.txt
git checkout -- file.txt  # Older syntax

Amend Last Commit

git commit --amend -m "new message"
git commit --amend --no-edit  # Keep message

Reset to Commit

git reset --soft HEAD~1   # Keep changes staged
git reset --mixed HEAD~1  # Keep changes unstaged
git reset --hard HEAD~1   # Discard changes

Revert Commit

git revert abc123       # Create undo commit

Recover Lost Commit

git reflog
git checkout abc123

Stash

6 snippets

Temporarily save changes

Stash Changes

git stash
git stash -m "work in progress"

List Stashes

git stash list

Apply Stash

git stash apply         # Keep stash
git stash pop           # Apply and remove

Apply Specific

git stash apply stash@{2}

Drop Stash

git stash drop stash@{0}
git stash clear         # Remove all

Stash Untracked

git stash -u            # Include untracked

Rebase

5 snippets

Rewrite commit history

Rebase onto Main

git checkout feature
git rebase main

Interactive Rebase

git rebase -i HEAD~3    # Last 3 commits
# pick, squash, edit, drop, reword

Continue Rebase

git rebase --continue

Abort Rebase

git rebase --abort

Squash Commits

# In interactive rebase:
# pick abc123 First commit
# squash def456 Second commit

Tags

5 snippets

Mark specific points in history

List Tags

git tag

Create Tag

git tag v1.0.0
git tag -a v1.0.0 -m "Release 1.0.0"

Tag Specific Commit

git tag v1.0.0 abc123

Push Tags

git push origin v1.0.0
git push origin --tags  # All tags

Delete Tag

git tag -d v1.0.0
git push origin --delete v1.0.0

More Cheat Sheets

FAQ

Frequently asked questions

What is a Git cheat sheet?

A Git cheat sheet is a quick reference guide containing the most commonly used syntax, functions, and patterns in Git. It helps developers quickly look up syntax without searching through documentation.

How do I learn Git quickly?

Start with the basics: variables, control flow, and functions. Use this cheat sheet as a reference while practicing. For faster learning, try DocuWriter.ai to automatically explain code and generate documentation as you learn.

What are the most important Git concepts?

Key Git concepts include variables and data types, control flow (if/else, loops), functions, error handling, and working with data structures like arrays and objects/dictionaries.

How can I document my Git code?

Use inline comments for complex logic, docstrings for functions and classes, and README files for projects. DocuWriter.ai can automatically generate professional documentation from your Git code using AI.

Code Conversion Tools

Convert Git to Other Languages

Easily translate your Git code to other programming languages with our AI-powered converters

Related resources

Stop memorizing. Start shipping.

Generate Git Docs with AI

DocuWriter.ai automatically generates comments, docstrings, and README files for your code.

Auto-generate comments
Create README files
Explain complex code
API documentation
Start Free - No Credit Card

Join 33,700+ developers saving hours every week