Git Reference
Every Git command, option, configuration setting, hook and file format in one place: concise, accurate pages with live examples that run against real Git 2.56, with syntax, options and common mistakes.
Setup and Basics
-
git initCreate a new repository. -
git cloneCopy a repository, with depth and filter options. -
git configRead and write configuration at every level. -
git helpOpen manual pages and guides. -
git versionShow the installed Git version and build options. -
git statusShow the state of the working tree and index. -
git varPrint Git logical variables such as the editor and identity. -
git credentialInterface to credential helpers. -
git maintenanceSchedule background repository upkeep.
Staging and Committing
-
git addStage file contents, hunks and deletions. -
git rmRemove files from the index and working tree. -
git mvMove or rename tracked files. -
git restoreRestore working tree files or unstage changes. -
git commitRecord staged changes as a commit. -
git commit --amendRewrite the most recent commit. -
git cleanRemove untracked files safely. -
git stashShelve changes and bring them back later. -
git update-index --assume-unchangedHide file changes from Git, and the skip-worktree flag. -
git sparse-checkoutCheck out only part of the tree.
Branches and Tags
-
git branchList, create, rename and delete branches. -
git switchChange branches or create a new one. -
git checkoutThe older all-purpose checkout command. -
git tagCreate, list and delete lightweight and annotated tags. -
git describeName a commit from the nearest tag. -
git show-branchCompare branch tips and their ancestry. -
git name-revFind symbolic names for revisions. -
git worktreeCheck out several branches at once. -
git for-each-refFormat and filter refs for scripts. -
git symbolic-refRead and change symbolic refs such as HEAD. -
git update-refSafely update a ref to a new object. -
git show-refList refs and verify they exist.
Merging and Rebasing
-
git mergeJoin histories with fast-forward or merge commits. -
Merge strategiesort, recursive, resolve, octopus, ours, subtree. -
git merge-baseFind the best common ancestor. -
git mergetoolResolve conflicts in an external tool. -
git rerereReuse recorded conflict resolutions. -
git rebaseReplay commits onto a new base. -
git rebase -iReorder, squash, edit and drop commits. -
git cherry-pickApply the changes of existing commits. -
git revertCreate a commit that undoes another. -
git resetMove HEAD and optionally the index and tree. -
git cherryFind commits not yet applied upstream. -
git range-diffCompare two versions of a patch series. -
git replayReplay commits without a working tree. -
git filter-branchLegacy history rewriting. -
git replaceSubstitute one object for another.
Inspecting History
-
git logBrowse commit history with filters and formats. -
git log --prettyFormat placeholders for log output. -
git showDisplay commits, tags, trees and blobs. -
git diffCompare commits, trees, index and working tree. -
git diff optionsWord diff, stat, algorithms and whitespace flags. -
git diff-treeCompare the content of two tree objects. -
git diff-indexCompare a tree with the index or working tree. -
git blameShow who last changed each line. -
git grepSearch tracked files and history. -
git shortlogSummarize history by author. -
git bisectBinary search for the commit that broke something. -
git reflogReview where refs used to point. -
git whatchangedLegacy log with raw diffs. -
git difftoolOpen changes in an external diff viewer. -
git notesAttach extra data to commits. -
git count-objectsReport loose objects and disk usage. -
git ls-filesList files in the index and working tree. -
git log -S and -GFind commits that add or remove a string.
Remotes and Collaboration
-
git remoteManage named remote repositories. -
git fetchDownload objects and refs without merging. -
git pullFetch and integrate in one step. -
git pushUpload commits and update remote refs. -
git push --force-with-leaseSafer forced pushes. -
git ls-remoteList refs in a remote repository. -
git submoduleEmbed other repositories at fixed commits. -
git subtreeMerge other repositories into a subdirectory. -
git request-pullGenerate a pull request summary. -
git format-patchPrepare commits as email patches. -
git amApply patches from a mailbox. -
git applyApply a diff to files or the index. -
git send-emailSend patches by email. -
git bundleMove history in a single file. -
git archiveExport a tree as a tar or zip file. -
git daemon and http-backendServe repositories over the network. -
Remote helpersgit-remote-* programs and custom URL schemes.
Maintenance and Recovery
-
git gcPack loose objects and prune garbage. -
git pruneDelete unreachable loose objects. -
git repackCombine objects into packfiles. -
git fsckVerify object database integrity. -
git pack-refsPack loose refs into one file. -
git commit-graphWrite the commit-graph acceleration file. -
git multi-pack-indexIndex across several packfiles. -
git verify-packInspect a packfile. -
git fast-importBulk-load history from a stream. -
git fast-exportDump history as a portable stream. -
scalarTuned setup for very large repositories. -
git bugreportCollect details for a bug report. -
git fsmonitor--daemonSpeed up status with a file system monitor.
Plumbing Commands
-
git cat-fileShow type, size and content of any object. -
git hash-objectCompute an object ID and optionally store it. -
git update-indexRegister file contents in the index. -
git write-treeCreate a tree object from the index. -
git read-treeRead a tree into the index. -
git commit-treeCreate a commit object from a tree. -
git mktreeBuild a tree from ls-tree style text. -
git mktagCreate a tag object with validation. -
git ls-treeList the contents of a tree object. -
git rev-parseResolve names to IDs and print repository paths. -
git rev-listList commits in reverse chronological order. -
git checkout-indexCopy files from the index to the working tree. -
git merge-fileThree-way merge of single files. -
git merge-treeCompute a merge without touching the tree. -
git check-ignoreDebug which ignore rule matches. -
git check-attrShow attributes applied to a path. -
git check-ref-formatValidate ref names. -
git ls-files --stageInspect index entries, modes and stages. -
git for-each-repoRun a command across configured repositories. -
git pack-objectsCreate a packfile from object IDs. -
git index-packBuild an index for a packfile. -
git unpack-objectsExplode a packfile into loose objects. -
git patch-idCompute a stable ID for a patch. -
git stripspaceClean up whitespace in text. -
git interpret-trailersAdd and parse commit message trailers. -
git mailinfoExtract patch and metadata from an email. -
git columnDisplay data in columns. -
git sh-setupHelper library for shell-based Git commands.
Revisions and Pathspecs
-
Revision syntaxNames, HEAD, branches, tags and abbreviated IDs. -
Caret and tildeHEAD^, HEAD~3, ^2 and combinations. -
@{n} and @{date}Reflog and time-based revision names. -
@{upstream} and @{push}Refer to tracking branches. -
A..B and A...BTwo-dot and three-dot range semantics. -
^rev and --notExclude revisions from a range. -
rev:path and :N:pathName blobs in commits and index stages. -
:/text and ^{/text}Find commits by message text. -
^{type} and ^{}Dereference tags to commits and trees. -
PathspecGlobs, directories and the -- separator. -
Pathspec magic:(glob), :(exclude), :(top), :(icase), :(attr). -
RefspecSource:destination mappings for fetch and push. -
Gitignore-style patternsWildcards, negation and anchoring. -
Git URLsssh, https, git and file forms and scp-like syntax. -
Date formatsISO, relative, raw and approxidate input.
Files and Formats
-
.gitignoreIgnore rules, precedence and negation. -
.git/info/excludeLocal ignore rules that are not committed. -
.gitattributesPer-path attributes for diffs, merges and line endings. -
text, eol and crlf attributesControl line-ending normalization. -
diff and merge attributesCustom drivers and binary handling. -
filter attributeClean and smudge filters, as used by LFS. -
export-ignore and export-substControl git archive contents. -
linguist-* attributesHints for GitHub language statistics. -
.gitmodulesSubmodule configuration file. -
.mailmapMap author names and emails. -
.git-blame-ignore-revsSkip formatting commits in blame. -
.gitconfig file formatSections, subsections, quoting and includes. -
include and includeIfShare and conditionally apply configuration. -
The .git directoryLayout of a repository on disk. -
.git file and commondirLinked worktrees and submodule git files. -
objects/info/alternatesShare objects between repositories. -
shallow and graftsShallow-clone boundaries and history grafts. -
sparse-checkout fileCone and non-cone patterns.
Configuration Options
-
user.*name, email, signingkey and useConfigOnly. -
core.editorChoose the commit message editor. -
core.autocrlfConvert line endings on checkout and commit. -
core.fileModeTrack the executable bit. -
core.ignoreCaseCase sensitivity on different file systems. -
core.excludesFileGlobal ignore file. -
core.hooksPathShare hooks across repositories. -
core.whitespaceWhitespace errors Git reports. -
core.pagerControl paging of output. -
core.fsmonitorFile-system monitor for fast status. -
init.defaultBranchName of the first branch. -
color.*Colorize output and customize colors. -
alias.*Define shortcuts and shell aliases. -
branch.*Tracking, rebase and merge options per branch. -
pull.rebase and pull.ffHow pull integrates changes. -
push.default and push.autoSetupRemoteWhat push sends by default. -
fetch.prune and fetch.parallelFetch behavior. -
merge.*Conflict style, ff, tool and drivers. -
rebase.*autosquash, autostash, updateRefs. -
diff.*Algorithm, renames, colorMoved, tool. -
log.*Date format, decorate, mailmap defaults. -
commit.*template, gpgsign, verbose, cleanup. -
gpg.*Signing format, program and SSH allowed signers. -
credential.*Helpers, cache and useHttpPath. -
http.*Proxy, SSL verification, extra headers. -
url.BASE.insteadOfRewrite remote URLs. -
protocol.*Allow or deny transports. -
safe.directoryTrust repositories owned by others. -
transfer.fsckObjectsVerify objects during transfers. -
gc.*Garbage collection thresholds. -
maintenance.*Scheduled tasks and strategies. -
submodule.*Recursion, update and branch tracking. -
status.*Short format, branch info, untracked files. -
help.autocorrectFix mistyped commands. -
rerere.enabledTurn conflict resolution recording on. -
feature.*Bundles of performance settings.
Hooks
-
Hooks overviewHow hooks run, arguments and exit codes. -
pre-commitCheck staged changes before a commit. -
prepare-commit-msgPrefill the commit message. -
commit-msgValidate the commit message. -
post-commitReact after a commit is created. -
pre-rebaseVeto a rebase. -
post-checkoutRun after switching branches or files. -
post-mergeRun after a merge completes. -
pre-pushCheck before sending to a remote. -
pre-receiveServer-side check of all pushed refs. -
updateServer-side check per ref. -
post-receiveServer-side action after a push. -
post-rewriteRun after amend or rebase. -
reference-transactionObserve every ref update. -
fsmonitor-watchmanIntegrate a file watcher. -
sendemail-validateCheck patches before send-email. -
Hook configurationMultiple hooks via config and hook.* settings.
Environment Variables
-
GIT_DIR and GIT_WORK_TREELocate the repository and working tree. -
GIT_AUTHOR_* and GIT_COMMITTER_*Set identity and dates for commits. -
GIT_EDITOR and GIT_PAGERChoose editor and pager. -
GIT_SSH_COMMANDCustomize the ssh invocation. -
GIT_CONFIG_*Override configuration from the environment. -
GIT_TRACE and friendsTrace commands, packets and performance. -
GIT_CURL_VERBOSEDebug HTTP transport. -
GIT_TERMINAL_PROMPTDisable interactive credential prompts. -
GIT_CEILING_DIRECTORIESLimit repository discovery. -
GIT_OBJECT_DIRECTORYRelocate or share the object store. -
GIT_INDEX_FILEUse a temporary index. -
GIT_EXEC_PATHWhere Git finds its subcommands. -
GIT_OPTIONAL_LOCKSAvoid lock contention in background tools.
Objects, Refs and Internals
-
Object modelBlobs, trees, commits and tags and how they link. -
Object IDs and SHA-256Hash algorithms and object-format. -
Loose object formatHeader, zlib compression and paths. -
Blob objectsFile contents without names. -
Tree objectsEntry modes, names and ordering. -
Commit objectsHeaders, parents, gpgsig and message. -
Tag objectsAnnotated tag layout and signatures. -
Packfile formatDeltas, offsets and pack index. -
Index file formatEntries, extensions and stage numbers. -
Refs and ref storageLoose refs, packed-refs and reftable. -
HEAD and detached HEADSymbolic versus direct HEAD. -
Special refsORIG_HEAD, MERGE_HEAD, FETCH_HEAD, CHERRY_PICK_HEAD. -
Commit-graph fileGeneration numbers and Bloom filters. -
Wire protocol v2How fetch and ls-refs talk over the wire. -
Unified diff formatHunks, headers and combined diffs. -
Email patch formatMbox layout produced by format-patch. -
Signed commits and tagsGPG, SSH and X.509 signatures.
Concepts
-
The staging areaWhy the index exists and how to use it. -
HEAD, index and working treeThe three trees behind reset and checkout. -
Merge versus rebaseWhen to use each and the golden rule. -
Reset modes compared--soft, --mixed, --hard and --keep. -
Detached HEADWhat it means and how to recover work. -
Fast-forward mergesWhen they happen and --no-ff. -
Merge conflict markersReading and resolving conflicts, diff3 style. -
Tracking branchesUpstream relationships explained. -
Plumbing and porcelainWhich commands are for scripts. -
Undoing thingsChoosing between restore, reset, revert and reflog. -
Line endingsCRLF, LF and cross-platform repositories. -
Large files and historyLFS, partial clone and shallow clone. -
Rewriting history safelyRisks, force pushes and recovery. -
Exit codes and scriptingWriting reliable shell scripts around Git. -
Common error messagesWhat typical Git errors mean and how to fix them. -
Command cheat sheetOne-page map of commands by task.
Nothing matches โโ. Try the site search.