Skip to content

Git commands and syntax

nivekyee edited this page Apr 24, 2021 · 8 revisions

How to understand command line syntax?

Reference: https://developers.google.com/style/code-syntax

Required items (commands, arguments, etc.)

Text without brackets or braces.

command
command --argument

Optional arguments

Text enclosed in square brackets.

command [--argument]

If there's more than one optional argument, each item is enclosed in its own set of square brackets.

command [--argument1] [--argument2]

Mutually exclusive arguments

If only one of the specified items should be chosen, the items are enclosed inside curly brackets (aka. braces), with vertical bars (aka. pipes) separating the options. There can be more than two mutually exclusive choices, separated from each other by pipes.

command {--argument1 | --argument2}
command {--required1 --also-required1 | --or-required2 [--optional2]}

Arguments that can repeat

Arguments that can have multiple values specified by the user are indicated with an ellipsis (...) .

command [--repeatable-argument ...]

User input

User provided information is enclosed in angle brackets (aka. chevrons).

command --argument <user-input>

List of git commands

For the complete list of all commands, see https://git-scm.com/docs.

Command Description Documentation
Setup and Config
git Git https://git-scm.com/docs/git
git-config Get and set repository or global options https://git-scm.com/docs/git-config
git-help Display help information about Git https://git-scm.com/docs/git-help
git-bugreport Collect information for user to file a bug report https://git-scm.com/docs/git-bugreport
Getting and Creating Projects
git-init Create an empty Git repository or reinitialize an existing one https://git-scm.com/docs/git-init
git-clone Clone a repository into a new directory https://git-scm.com/docs/git-clone
Basic Snapshotting
git-add Add file contents to the index https://git-scm.com/docs/git-add
git-status Show the working tree status https://git-scm.com/docs/git-status
git-diff Show changes between commits, commit and working tree, etc https://git-scm.com/docs/git-diff
git-commit Record changes to the repository https://git-scm.com/docs/git-commit
git-notes Add or inspect object notes https://git-scm.com/docs/git-notes
git-restore Restore working tree files https://git-scm.com/docs/git-restore
git-reset Reset current HEAD to the specified state https://git-scm.com/docs/git-reset
git-rm Remove files from the working tree and from the index https://git-scm.com/docs/git-rm
git-mv Move or rename a file, a directory, or a symlink https://git-scm.com/docs/git-mv
Branching and Merging*
git-branch List, create, or delete branches https://git-scm.com/docs/git-branch
git-checkout Switch branches or restore working tree files https://git-scm.com/docs/git-checkout
git-switch Switch branches https://git-scm.com/docs/git-switch
git-merge Join two or more development histories together https://git-scm.com/docs/git-merge
git-mergetool Run merge conflict resolution tools to resolve merge conflicts https://git-scm.com/docs/git-mergetool
git-log Show commit logs https://git-scm.com/docs/git-log
git-stash Stash the changes in a dirty working directory away https://git-scm.com/docs/git-stash
git-tag Create, list, delete or verify a tag object signed with GPG https://git-scm.com/docs/git-tag
git-worktree Manage multiple working trees https://git-scm.com/docs/git-worktree
Sharing and Updating Projects
git-fetch Download objects and refs from another repository https://git-scm.com/docs/git-fetch
git-pull Fetch from and integrate with another repository or a local branch https://git-scm.com/docs/git-pull
git-push Update remote refs along with associated objects https://git-scm.com/docs/git-push
git-remote Manage set of tracked repositories https://git-scm.com/docs/git-remote
git-submodule Initialize, update or inspect submodules https://git-scm.com/docs/git-submodule
Inspection and Comparison*
git-show Show various types of objects https://git-scm.com/docs/git-show
git-log Show commit logs https://git-scm.com/docs/git-log
git-diff Show changes between commits, commit and working tree, etc https://git-scm.com/docs/git-diff
git-difftool Show changes using common diff tools https://git-scm.com/docs/git-difftool
git-range-diff Compare two commit ranges (e.g. two versions of a branch) https://git-scm.com/docs/git-range-diff
git-shortlog Summarize git log output https://git-scm.com/docs/git-shortlog
git-describe Give an object a human readable name based on an available ref https://git-scm.com/docs/git-describe
Patching
git-apply Apply a patch to files and/or to the index https://git-scm.com/docs/git-apply
git-cherry-pick Apply the changes introduced by some existing commits https://git-scm.com/docs/git-cherry-pick
git-diff Show changes between commits, commit and working tree, etc https://git-scm.com/docs/git-diff
git-rebase Reapply commits on top of another base tip https://git-scm.com/docs/git-rebase
git-revert Revert some existing commits https://git-scm.com/docs/git-revert
Debugging
git-bisect Use binary search to find the commit that introduced a bug https://git-scm.com/docs/git-bisect
git-blame Show what revision and author last modified each line of a file https://git-scm.com/docs/git-blame
git-grep Print lines matching a pattern https://git-scm.com/docs/git-grep

Clone this wiki locally