API reference
Git API reference
Version control from the command line
Last updated
- Identifiers
- 66
- With full guides
- 49
- Types
- 3
Topics covered
- Commits
- Branches
- Merging & rebasing
- Remotes
- History
- Hooks
Command
| Name | What it does |
|---|---|
git init | git init creates a new, empty Git repository, or reinitializes one that already exists. It is usually the first command you run to put a project under version control. |
git clone | git clone copies an existing repository into a new directory. It sets up remote-tracking branches for every branch in the source and checks out a starting branch based on the source's active branch. |
git add | git add copies the current content of new or changed files into the index (the staging area), which holds what the next commit will contain. A plain git commit records only what has been staged. |
git status | git status reports the state of your working tree. It lists what is staged for the next commit, what has changed but is not staged, and which files Git is not tracking. |
git commit | git commit records a new snapshot in the repository from the current contents of the index, together with a log message. The new commit becomes a child of HEAD, and the current branch moves forward to point at it. |
git diff | git diff shows line-level differences between two snapshots in a repository: the working tree, the index (staging area), commits, trees, or blobs. Outside a repository, or with --no-index, it compares two paths on disk. |
git log | git log shows commit history. It lists the commits you can reach from the starting points you give, newest first, and you can filter, order and format that list. |
git show | git show prints one or more Git objects in a readable form: a commit, an annotated tag, a tree, or a blob. With no argument it shows HEAD, the latest commit on the current branch. |
git branch | git branch manages branches. It can list, create, rename, copy and delete them, and it can set or change the upstream branch each one follows. |
git switch | git switch moves you onto a different branch. It can also create a branch, reset one, detach HEAD at a commit, or start an orphan branch as part of the same command. |
git checkout | git checkout either moves you to another branch or commit, or overwrites chosen files with the version stored in the index or in a given commit. It is the older all-in-one command whose two jobs are now also covered separately by git switch and git restore. |
git merge | git merge brings the changes from one or more named commits, usually branch tips, into the current branch. Depending on the history, it either moves the branch pointer forward (a fast-forward) or records a new merge commit with several parents. |
git rebase | git rebase takes the commits that are unique to a branch and replays them on a different base commit, creating new commits. It can also rewrite a branch in place by reordering, editing, squashing or dropping commits in interactive mode. |
git cherry-pick | git cherry-pick takes the changes made by one or more existing commits and replays them on your current branch, making a new commit for each one. It is the usual way to copy specific fixes between branches without merging the whole branch. |
git stash | git stash saves your uncommitted changes to the working tree and index, then resets them to match HEAD so your directory is clean. You can bring the saved changes back later, either on the same commit or on a different one. |
git tag | git tag creates, lists, deletes and verifies tags. Tags are names stored under refs/tags/ that mark a specific object, usually a commit such as a release point. |
git fetch | git fetch downloads commits, trees, blobs and refs (branches and tags) from one or more other repositories and updates your remote-tracking branches. It does not merge anything into your own branches or change your working tree. |
git pull | git pull brings changes from another repository, or from a local branch, into the branch you have checked out. It runs a fetch and then integrates the fetched branch by fast-forwarding, rebasing, merging or squashing. |
git push | git push copies your local commits to a remote repository and moves that remote's branches, tags or other refs to match. It sends only the objects the remote does not already have. |
git remote | git remote manages the named remote repositories your local repository tracks. You use it to list, add, rename, remove and inspect remotes and their URLs and tracked branches. |
git reset | git reset either moves the current branch tip (HEAD) to another commit, or changes what is staged for chosen paths. You use it to undo commits, merges and pulls, or to unstage files. |
git revert | git revert undoes the effect of one or more existing commits by adding new commits that apply the opposite changes. It does not rewrite history, so it is the safe way to undo work that has already been shared. |
git restore | git restore puts selected paths back to the content held in a restore source. It can undo working-tree edits, unstage changes, or bring back a file as it was in an older commit. |
git rm | git rm removes tracked files from the index, or from both the index and the working tree. Committing afterwards records the deletion. |
git mv | git mv renames or moves a tracked file, directory or symlink in your working tree. In the same step it records that change in the index (staging area). |
git blame | git blame shows, for every line of a file, which commit last changed that line, along with its author and date. Use it to find out where a specific piece of code came from. |
git bisect | git bisect does a binary search through commit history to find the commit that introduced a bug. More generally, it finds the commit where any testable property of the project changed. |
git reflog | git reflog shows and manages reference logs. These are local records of every position a branch tip, HEAD or another ref has pointed to, so you can find and restore earlier states. |
git clean | git clean deletes untracked files from your working tree. It can also delete untracked directories and files that Git ignores, so you can get back to a pristine checkout. |
git config | git config reads, writes, and removes Git settings. These settings live in system, global (per-user), repository, and worktree config files, and they change how other Git commands behave. |
git worktree | git worktree lets one repository have several working directories, so you can check out more than one branch at once. Its subcommands add, list, lock, unlock, move, remove, prune and repair these linked worktrees. |
git submodule | git submodule lets you add, initialize, update, inspect and manage submodules. A submodule is another Git repository nested inside a superproject and pinned to a specific commit. |
git grep | git grep searches text for patterns inside a Git repository. It can search the tracked files in your working tree, the staged content in the index, or any commit or tree, without checking that tree out. |
git shortlog | git shortlog condenses commit history into a list grouped by contributor, with each person's commit subjects under their name. It is meant for release notes and contributor statistics. |
git describe | git describe gives a commit a readable name based on the nearest tag it can reach, such as v1.0.4-14-g2414721. Release scripts and build tools often use it to create version strings. |
git archive | git archive packs the files of one commit, tag or tree into a tar or zip archive. It works straight from repository objects and does not need a checkout, so it is the usual way to build source release tarballs. |
git format-patch | git format-patch turns a range of commits into email-ready patch files, one per non-merge commit, in UNIX mbox style. It keeps the author, date and commit message, so the recipient can rebuild the same commits with git am or send them with git send-email. |
git am | git am takes patches that arrive as email, in a mailbox file or a Maildir, and turns each one into a commit on the current branch. It keeps the original author, date and message, so it does the reverse of git format-patch. |
git apply | git apply reads a diff (a patch) and applies it to files in the working tree, the index, or both. It does not create a commit. Use git am when you want commits made from mailed or format-patch patches. |
git gc | git gc does housekeeping on your local repository. It compresses objects into packfiles, throws away unreachable data once it has aged enough, and tidies refs, reflogs, rerere records and worktree metadata so the repository takes less disk space and runs faster. |
git fsck | git fsck checks a repository's object database for integrity. It confirms that objects are valid and that everything they refer to is present, then reports corruption, missing objects and objects that nothing points to. |
git rerere | git rerere ("reuse recorded resolution") remembers how you resolved a merge conflict. When the same conflict shows up again, Git applies your earlier fix for you. |
git sparse-checkout | git sparse-checkout limits your working tree to a chosen subset of tracked files. You can also use it to change that subset later or to bring back the full checkout. |
git notes | git notes lets you attach, read, change and remove extra text (notes) on Git objects, usually commits, without touching the objects. The commit hash stays the same, so you can annotate history that has already been published. |
git ls-files | git ls-files is a low-level (plumbing) command that lists files by comparing what's in Git's index with what's in your working directory. Flags pick which groups to show: tracked, modified, deleted, untracked, ignored or unmerged. |
git rev-parse | git rev-parse is a low-level plumbing command. It turns revision expressions such as HEAD~2 or v1.0^{commit} into object names, and it can also report details about the repository, such as its top-level path, whether you are inside a work tree, and the current branch. |
git bundle | git bundle packs Git objects and refs into a single file. You can move that file by USB, email or any other channel and clone or fetch from it later, with no network connection between the two repositories. |
Concept
| Name | What it does |
|---|---|
Working tree | The working tree is the directory of real, checked-out files that you edit. It usually starts from the tree of the HEAD commit and also holds any local changes you have not committed yet. |
Staging area | The staging area, which Git also calls the index, is one of Git's four core kinds of data. It holds the exact file snapshot your next commit will record, so you can choose what goes into a commit separately from what is in your working directory. |
HEAD | |
Commit graph | |
Detached HEAD | |
Fast-forward merge | |
Merge conflict | |
Upstream branch | |
Trunk-based development | |
Git Flow | |
Conventional Commits | |
Signed commits |
Option
| Name | What it does |
|---|---|
.gitignore | |
.gitattributes | |
.gitconfig | |
pre-commit hook | |
commit-msg hook | |
pre-push hook | |
post-merge hook |
Search across every package and filter by type in your dashboard.
Start learning