GitCommand Reference

Complete Git Command Reference

A comprehensive reference covering every major Git command, organised by porcelain (user-facing) and plumbing (low-level) commands. Includes key flags, environment variables, and configuration keys.

Porcelain vs Plumbing Commands

Category

Description

Examples

Porcelain

High-level, user-facing commands with stable interfaces

git add, git commit, git push, git pull

Plumbing

Low-level internal commands; output is machine-parseable

git cat-file, git hash-object, git update-ref

Porcelain commands call plumbing commands internally. Scripts should use plumbing commands for reliable, parseable output; humans use porcelain for everyday work.

Porcelain Commands — A to D

Command

Syntax

Description

git add

git add [...]

Add file contents to the index (staging area)

git am

git am [...]

Apply patches from a mailbox

git archive

git archive [--format=]

Create a tar/zip archive of a tree

git bisect

git bisect <start|good|bad|reset>

Binary search to find the commit introducing a bug

git blame

git blame [-L ,]

Show what revision and author last modified each line

git branch

git branch [] []

List, create, or delete branches

git bundle

git bundle create []

Create a portable bundle of commits

git checkout

git checkout [-b] <branch|file>

Switch branches or restore working tree files

git cherry-pick

git cherry-pick ...

Apply the changes from one or more commits

git clean

git clean [-f] [-d] [-x]

Remove untracked files from the working tree

git clone

git clone [--depth=N] [

]

Clone a repository into a new directory

git commit

git commit [-m ] [-a]

Record changes to the repository

git describe

git describe [--tags] []

Describe a commit using the most recent reachable tag

git diff

git diff [] [] [--] []

Show changes between commits, trees, or working tree

Porcelain Commands — F to M

Command

Syntax

Description

git fetch

git fetch [] []

Download objects and refs from remote without merging

git format-patch

git format-patch [-N] |

Prepare patches suitable for email submission

git gc

git gc [--aggressive]

Cleanup unnecessary files, optimise the local repository

git grep

git grep [-n] [-l] [-i]

Print lines matching a pattern in tracked files

git init

git init [--bare] [

]

Create an empty Git repository or reinitialise one

git log

git log [] [] [[--] ]

Show the commit log

git maintenance

git maintenance start|stop|run

Schedule background repository maintenance tasks

git merge

git merge [--no-ff] [--squash]

Join two or more development histories together

git mergetool

git mergetool [--tool=]

Run a merge conflict resolution tool

git mv

git mv

Move or rename a file, directory, or symlink

Porcelain Commands — P to Z

Command

Syntax

Description

git pull

git pull [--rebase] [] []

Fetch and integrate with another repo or local branch

git push

git push [-u] [--force-with-lease]

Update remote refs along with associated objects

git rebase

git rebase [-i] [--onto ]

Reapply commits on top of another base tip

git reflog

git reflog [show|expire|delete]

Manage reflog information (history of HEAD movements)

git remote

git remote [-v] [add|remove|rename]

Manage set of tracked remote repositories

git reset

git reset [--soft|--mixed|--hard] []

Reset current HEAD to the specified state

git restore

git restore [--staged] [--source=]

Restore working tree files

git revert

git revert [-n] ...

Revert existing commits by creating new inverse commits

git rm

git rm [--cached] [-f]

Remove files from the working tree and index

git shortlog

git shortlog [-sn] []

Summarise git log output

git show

git show []

Show various types of Git objects

git sparse-checkout

git sparse-checkout init|set|add|disable

Reduce working tree to a subset of tracked files

git stash

git stash push|pop|list|drop|apply|show

Stash working directory changes temporarily

git status

git status [-s] [-b]

Show working tree status relative to index and HEAD

git submodule

git submodule add|update|init|sync|status

Initialize, update, or inspect submodules

git switch

git switch [-c]

Switch branches (modern replacement for checkout)

git tag

git tag [-a] [-m ] []

Create, list, delete, or verify a tag object

git worktree

git worktree add|list|remove

Manage multiple working trees

Plumbing Commands

Command

Syntax

Description

git cat-file

git cat-file -t|-s|-p

Inspect content, type, or size of repository objects

git commit-tree

git commit-tree -m

Create a new commit object (low-level)

git for-each-ref

git for-each-ref [--format=] []

Output information about refs

git hash-object

git hash-object [-w]

Compute SHA-1 of a file and optionally store it

git ls-files

git ls-files [-m] [-o] [-s]

Show information about files in the index/working tree

git ls-remote

git ls-remote

List references in a remote repository

git ls-tree

git ls-tree [-r]

List the contents of a tree object

git merge-base

git merge-base

Find the best common ancestor between commits

git pack-objects

git pack-objects

Create a packed archive of objects

git read-tree

git read-tree

Read tree information into the index

git rev-list

git rev-list [] ...

List commit objects in reverse chronological order

git rev-parse

git rev-parse [--short]

Parse revision parameters, print the SHA

git show-ref

git show-ref [--heads] [--tags]

List references in a local repository

git symbolic-ref

git symbolic-ref HEAD

Read or write symbolic refs (like HEAD)

git update-index

git update-index --chmod=+x

Register file contents in the index

git update-ref

git update-ref

Update the object name stored in a ref safely

git write-tree

git write-tree

Create a tree object from the current index

git log — Key Flags Reference

git log flags in action

Bash
# Pretty formats
git log --oneline              # <hash> <subject>
git log --format="%H %ae %s"   # full hash, author email, subject
git log --graph --oneline --all  # ASCII branch graph

# Filtering
git log --author="Alice"       # commits by author
git log --since="2 weeks ago"  # recent commits
git log --until="2026-01-01"   # commits before a date
git log --grep="fix"           # commits matching a pattern in message
git log --all --full-history -- deleted-file.ts  # find deleted file history

# Diff output
git log -p                     # show patch (diff) for each commit
git log --stat                 # show files changed + lines
git log --name-only            # show only filenames changed
git log --name-status          # show filenames with A/M/D status

# Range
git log main..feature          # commits on feature not on main
git log main...feature         # commits unique to either side (symmetric diff)
git log HEAD~5..HEAD           # last 5 commits
git diff — Key Flags Reference

git diff flag combinations

Bash
git diff                        # unstaged changes
git diff --staged               # staged changes (also --cached)
git diff HEAD                   # all changes since last commit

git diff <branch1>..<branch2>   # all differences between tips
git diff <branch1>...<branch2>  # changes on branch2 since divergence

git diff --stat                 # files changed + insertion/deletion counts
git diff --name-only            # only file names
git diff --word-diff            # highlight changed words, not lines
git diff -w                     # ignore all whitespace
git diff -b                     # ignore whitespace-only changes
Environment Variables

Variable

Effect

GIT_DIR

Path to the .git directory (default: .git)

GIT_WORK_TREE

Path to the working tree (when GIT_DIR is set)

GIT_AUTHOR_NAME

Override author name for the current commit

GIT_AUTHOR_EMAIL

Override author email for the current commit

GIT_AUTHOR_DATE

Override author date (format: RFC2822 or ISO8601)

GIT_COMMITTER_NAME

Override committer name

GIT_COMMITTER_EMAIL

Override committer email

GIT_COMMITTER_DATE

Override committer date

GIT_SSH_COMMAND

SSH command to use (e.g. to specify a key file)

GIT_TERMINAL_PROMPT

Set to 0 to disable terminal prompting (CI use)

GIT_TRACE

Enable trace logging (=1 or =file path)

GIT_TRACE_PERFORMANCE

Enable performance tracing

GIT_CURL_VERBOSE

Enable verbose curl output for HTTP operations

GIT_MERGE_VERBOSITY

Control merge verbosity (0-5)

GIT_PAGER

Pager to use (default: PAGER or less)

GIT_EDITOR

Editor to use (overrides EDITOR)

GIT_DIFF_OPTS

Default options for git diff

GIT_CONFIG_NOSYSTEM

Set to 1 to ignore /etc/gitconfig

GIT_INDEX_FILE

Path to the index file

GIT_OBJECT_DIRECTORY

Path to the objects directory

Git Configuration Keys Reference

Config key

What it controls

user.name

Author name in commits

user.email

Author email in commits

user.signingKey

GPG key ID for signing commits

core.editor

Editor for commit messages and interactive operations

core.pager

Pager for long output (default: less)

core.autocrlf

Line ending conversion (true/false/input)

core.fileMode

Whether to track file permissions changes

core.ignoreCase

Case-insensitive file system (auto-detected)

core.fsmonitor

Enable file system monitor for faster status

core.untrackedCache

Cache untracked files for faster status

commit.gpgSign

Sign all commits with GPG (true/false)

commit.template

Path to a commit message template file

branch.autoSetupMerge

Auto track remote branch when creating local (true/always/false)

branch.autosetuprebase

Set pull to rebase instead of merge for new branches

push.default

Behaviour of git push with no args (current/simple/matching/upstream)

push.followTags

Automatically push tags that point to pushed commits

pull.rebase

Rebase instead of merge on git pull (true/false/merges)

fetch.prune

Automatically remove remote-tracking refs no longer on remote

fetch.writeCommitGraph

Update commit-graph after fetch

merge.tool

Merge tool to use (vimdiff, kdiff3, etc.)

merge.conflictStyle

Style of conflict markers (merge/diff3/zdiff3)

rebase.autoSquash

Automatically apply fixup!/squash! commits in interactive rebase

rebase.autoStash

Stash before rebase and pop after

diff.colorMoved

Colour moved code differently (default/zebra/blocks)

diff.algorithm

Diff algorithm (myers/minimal/patience/histogram)

help.autoCorrect

Auto-run corrected command after N tenths of a second

http.sslVerify

Verify SSL certificates (set to false only for testing)

http.proxy

HTTP proxy URL

alias.*

Command aliases (e.g. alias.st = status)

includeIf.gitdir:~/work/.path

Conditionally include config for repos in a directory

Note
Configuration is read in this priority order (last wins): system (`/etc/gitconfig`), global (`~/.gitconfig`), local (`.git/config`), worktree (`.git/config.worktree`), command-line (`-c key=value`).
Refspec Syntax

Refspec format and examples

Bash
# Format: [+]<src>:<dst>
# + = force update even if non-fast-forward
# src = source ref on remote
# dst = destination ref locally

# Fetch a remote branch to a local branch
git fetch origin refs/heads/main:refs/remotes/origin/main

# Push local branch to differently-named remote branch
git push origin feature/auth:feature/authentication

# Delete a remote branch (empty src)
git push origin :old-branch-name
# Equivalent to:
git push origin --delete old-branch-name

# Fetch all remote branches
git fetch origin 'refs/heads/*:refs/remotes/origin/*'

# Push all local tags
git push origin 'refs/tags/*:refs/tags/*'
Tip
Run `git help <command>` or `man git-<command>` for the full manual page of any command. `git help -a` lists all available commands. `git help -g` lists available guides (gitworkflows, giteveryday, etc.).