Docsity

Git Command Cheat Sheet PDF 2026: Complete CLI Reference Guide for Developers, Cheat Sheet of Computer Science

Toggle sidebar
bg1
Git Command Cheat Sheet
High-Yield Reference & Architecture Blueprint for Developers
MASTER EDITION
The Git Architecture Overview:
Git manages
fi
les across three local areas: the
Working Directory
(untracked/modi
fi
ed
fi
les), the
Staging Area/Index
(prepared for commit), and the
Local Repository
(committed snapshots). Remote repositories extend this
work
fl
ow to teams.
Working Directory
Local modi
fi
ed
fi
les
Unstaged
Staging Area (Index)
Prepared changes
Index
Local Repository
Committed HEAD (.git)
Local Commits
Remote Repo
GitHub / GitLab
origin/main
git add
commit
push
fetch / pull
1. SETUP & ENVIRONMENT CONFIGURATION
COMMAND DESCRIPTION & HIGH-YIELD USAGE
git config --global user.name "[name]"
Sets author name attached to all local commits.
git config --global user.email "[email]"
Sets author email address attached to local commits.
git config --global core.editor "[editor]"
Con
fi
gures default text editor (e.g.,
code --wait
,
vim
).
git config --global init.defaultBranch main
Sets default branch name to 'main' for newly initialized repositories.
git config --list
Lists all global and repository-level con
fi
gurations.
2. CREATING & INITIALIZING REPOSITORIES
COMMAND DESCRIPTION & HIGH-YIELD USAGE
git init
Initializes a new Git repository in the current working directory.
git init [project-name]
Creates a new folder and initializes an empty Git repository inside it.
git clone [url]
Downloads full repository, history, and branches from remote host.
git clone --depth 1 [url]
Shallow clone: downloads only the latest commit (saves bandwidth/time).
3. BASIC SNAPSHOTTING & STAGING WORKFLOW
COMMAND DESCRIPTION & HIGH-YIELD USAGE
git status
Shows state of working tree (tracked, untracked, modi
fi
ed, staged).
git status -s
Displays status in compact short-format.
git add [file]
Stages a speci
fi
c
fi
le for the next commit.
git add .
Stages all modi
fi
ed, new, and deleted
fi
les in current directory tree.
git add -p
Interactive patch mode: select speci
fi
c hunks of changes to stage.
git commit -m "[message]"
Records staged snapshot permanently in version history with message.
Git Command Cheat Sheet
•
Master Reference Edition Page 1 of 3
pf3

Partial preview of the text

Download Git Command Cheat Sheet PDF 2026: Complete CLI Reference Guide for Developers and more Cheat Sheet Computer Science in PDF only on Docsity!

Git Command Cheat Sheet

High-Yield Reference & Architecture Blueprint for Developers

MASTER EDITION

The Git Architecture Overview: Git manages files across three local areas: the Working Directory (untracked/modified files), the Staging Area/Index (prepared for commit), and the Local Repository (committed snapshots). Remote repositories extend this workflow to teams.

Working Directory Local modified files

Unstaged

Staging Area (Index) Prepared changes

Index

Local Repository Committed HEAD (.git)

Local Commits

Remote Repo GitHub / GitLab

origin/main

git add commit push

fetch / pull

1. SETUP & ENVIRONMENT CONFIGURATION

COMMAND DESCRIPTION & HIGH-YIELD USAGE

git config --global user.name "[name]" Sets author name attached to all local commits.

git config --global user.email "[email]" Sets author email address attached to local commits.

git config --global core.editor "[editor]" Configures default text editor (e.g., code --wait , vim ).

git config --global init.defaultBranch main Sets default branch name to 'main' for newly initialized repositories.

git config --list Lists all global and repository-level configurations.

2. CREATING & INITIALIZING REPOSITORIES

COMMAND DESCRIPTION & HIGH-YIELD USAGE

git init Initializes a new Git repository in the current working directory.

git init [project-name] Creates a new folder and initializes an empty Git repository inside it.

git clone [url] Downloads full repository, history, and branches from remote host.

git clone --depth 1 [url] Shallow clone: downloads only the latest commit (saves bandwidth/time).

3. BASIC SNAPSHOTTING & STAGING WORKFLOW

COMMAND DESCRIPTION & HIGH-YIELD USAGE

git status Shows state of working tree (tracked, untracked, modified, staged).

git status -s Displays status in compact short-format.

git add [file] Stages a specific^ file for the next commit.

git add. Stages all modified, new, and deleted^ files in current directory tree.

git add -p Interactive patch mode: select specific hunks of changes to stage.

git commit -m "[message]" Records staged snapshot permanently in version history with message.

4. BRANCHING & CONTEXT SWITCHING

COMMAND DESCRIPTION & HIGH-YIELD USAGE

git branch Lists all local branches. Current active branch marked with an asterisk (*).

git branch -a Lists all local AND remote-tracking branches.

git branch [branch-name] Creates a new branch pointer at current HEAD commit without switching.

git switch [branch-name] Switches to target branch (Modern alternative to git checkout ).

git switch -c [branch-name] Creates and immediately switches to new branch.

git branch -d [branch-name] Deletes specified branch safely (refuses if unmerged changes exist).

git branch -D [branch-name] Force deletes a branch regardless of merge status. Use caution.

git branch -m [new-name] Renames the currently active branch.

5. MERGING, REBASING & HISTORY CLEAN-UP

COMMAND DESCRIPTION & HIGH-YIELD USAGE

git merge [branch] Merges named branch into current branch, creating a merge commit.

git merge --no-ff [branch] Forces a explicit merge commit even if fast-forward is possible.

git rebase [base-branch] Re-applies current branch commits on top of [base-branch] for linear history.

git rebase -i HEAD~[N] Interactive rebase for last N commits: squash, reword,^ fixup, or drop commits.

git rebase --abort Cancels an in-progress rebase operation and restores original state.

git cherry-pick [commit-hash] Applies changes introduced by specific commit to current branch.

Golden Rule of Rebasing: Never rebase commits that have already been pushed to a shared public repository. Rebasing rewrites commit hashes and will create divergent histories for team members.

6. INSPECTION, LOGS & DIFF ANALYSIS

COMMAND DESCRIPTION & HIGH-YIELD USAGE

git log Displays commit history in reverse chronological order.

git log --oneline --graph --all Displays condensed ASCII visual branch graph of all commits.

git log -p -n [count] Shows diff patch output for the last N commits.

git diff Shows unstaged changes between working directory and staging index.

git diff --staged Shows staged changes prepared for commit vs. last commit.

git diff branchA..branchB Displays line-by-line differences between two branches.

git blame [file] Annotates each line of^ file with commit hash, author, and timestamp.