git clone’s man page | Clone a repository into a new directory. |
git clone <bare repository directory> | Create a repository which is the clone of a bare repository. |
git clone <bare repository directory> <my directory name> | Create a repository with name <my directory name> which is the clone of a bare repository (if <my directory name> is not specified, the name of the remote repository is used). |
git clone --bare <path to directory containing .git> | Create a bare repository which is the clone of a repository. |
git clone --single-branch | Clone only the history leading to the tip of a single branch, either specified by the --branch option or the primary branch remote’s HEAD points at. |
git clone --depth <depth> | Create a shallow clone with a history truncated to the specified number of commits. Imply --single-branch unless --no-single-branch is given to fetch the histories near the tips of all branches. |
git clone --recurse-submodules | Clone all submodules. |
git clone --quiet
git clone -q | Progress is not reported to the standard error stream. |
git clone --verbose
git clone -v | Run verbosely, but progress is reported as usual on stderr. |
git clone --config <key>=<value>
git clone -c <key>=<value> | Set a configuration variable in the created repository, after the repository is initialised, before the remote history is fetched or any files checked out. |
git clone --no-checkout
git clone -n | No checkout of HEAD is performed after the clone is complete. |
git clone --branch <branch>
git clone -b <branch> | Set the HEAD to the specified branch after the clone is complete and check out that branch. |
git remote’s man page | List the upstream and downstream repositories. |
git log’s man page | Show commit logs. |
git log --all | Pretend as if all the refs in refs/, along with HEAD, are listed on the command line as <commit>. |
git log --full-history | Do not prune some history as the default mode (useful to see the merges). |
-- | Separate paths from revisions.
git log -- **/*.md will show logs of commits impacting the Markdown files. |
-L<start>,<end>:<file>
-L:<funcname>:<file> | Show the code changes for a part of a file.
<start> and <end> are numbers or regexps.
<end> can be defined as an offset.
<funcname> is a regexp. |
git log --full-history | Does not prune some history. |
git log --full-history --simplify-merges | Same as --full-history but remove some needless merges. |
git log --full-history -- <myfile> | Display the log of a file even if this one does not exist anymore. |
git log -<n> | Limit the log to the n last commits. |
git log --since "2020-09-05 00:00" --until "2020-09-06 24:00" | Limit the log between two datetimes. |
git log --committer=<regex> | Filter on a given committer (if there are several --committer flags, return commits of committers matching any of the regexps). |
git log --author=<regex> | Filter on a given author (if there are several --author flags, return commits of authors matching any of the regexps). |
git log --grep=<regexp> | Filter the commits to the ones with log message that matches the specified pattern (regular expression).
With more than one --grep=<regexp>, commits whose message matches any of the given patterns are chosen.
With more than one --grep=<regexp> and ---all-match, limit the commits output to ones that match all given regular expressions. |
--invert-grep | Limit the commits output to ones with log message that do not match. |
-i
--regexp-ignore-case | Match the regular expression limiting patterns without regard to letter case. |
--basic-regexp | Consider the limiting patterns to be basic regular expressions; this is the default. |
-E
--extended-regexp | Consider the limiting patterns to be extended regular expressions instead of the default basic regular expressions. |
-F
--fixed-strings | Consider the limiting patterns to be fixed strings. |
-P
--perl-regexp | Consider the limiting patterns to be Perl-compatible regular expressions. |
git log -S<string> | Look for differences that change the number of occurrences of the specified string. |
git log -S<regexp> --pickaxe-regex | Look for differences that change the number of occurrences of the specified regexp. |
git log -G<regexp> | Look for differences whose patch text contains added/removed lines that match the specified regular expression.
(Use git log -G<regexp> -p to display all the matching changes.
Use git log -G<regexp> --all to look in all branches.) |
--pickaxe-all | When -S or --G finds a change, show all the changes in that changeset, not just the files that contain the string/regexp. |
git log --pretty=<format> | Show more and more information.
- oneline
- short
- medium
- full
- fuller
|
git log --pretty="%cI %s" | Show the commit date and the commit subject. |
git log --pretty="%ce,%cd" --date=short > commits.csv | Dump the authors and dates of the commits in a file. |
git log --name-only | Show only names of changed files. |
git log --name-status | Show only names and status of changed files. |
git log --abbrev-commit | Instead of showing the full 40-byte hexadecimal commit object name, show a prefix that names the object uniquely. |
git log --oneline | Shorthand for --pretty=oneline --abbrev-commit. |
git log decorate
git log decorate=short | Print out the ref names of any commits that are shown. The ref name prefixes refs/heads/, refs/tags/, and refs/remotes/ are not printed. |
git log decorate=long | Print out the full ref names of any commits that are shown. |
git log decorate=auto | If the output is going to a terminal, the ref names are shown as if short was given, otherwise no ref names are shown. |
git log --stat | Indicate the modified files with a graph of the stats of the changes. |
git log --shortstat | Indicate the numbers of modified files, added and deleted lines. |
git log -p
git log --patch | Show the code changes in each commit. |
git log -U<n>
git log --unified=<n> | Generate diffs with n lines of context instead of the usual 3. Implies -p. |
git log --graph | Draw a text-based graphical representation. |
git log --reverse | Output the commits chosen to be shown in reverse order. |
git whatchanged’s man page | Show logs with difference each commit introduces. |
git whatchanged | List the last commits: hash, author, date, and list of impacted files. |
git shortlog’s man page | Summarize git log output. |
git shortlog -n
git shortlog --numbered | Sort output according to the number of commits per author instead of author alphabetic order. |
git shortlog -s
git shortlog --summary | Suppress commit description and provide a commit count summary only. |
git shortlog -e
git shortlog --email | Show the email address of each author. |
git shortlog -nse | List of authors with their emails sorted by number of commits. |
git stash’s man page | Stash the changes in a dirty working directory away. |
git stash
git stash push | Save local modifications away and revert the working directory to match the HEAD commit (in the working tree and in the index). |
git stash push --message <message>
git stash push -m <message> | Attach a description to the stashed state. |
git stash push --keep-index | All changes already added to the index are left intact. |
git stash push --include-untracked
git stash push --all
git stash -u
git stash -a | --include-untracked, -u: all untracked files are also stashed and then cleaned up with git clean
--all, -a: the ignored files are stashed and cleaned in addition to the untracked files. |
git stash push -u foo.txt bar.txt new.txt | Stash a list of modified and new files. |
git stash push -p
git stash push --patch | Interactively select hunks from the diff between HEAD and the working tree to be stashed. |
git stash list | List the stashed entries. |
git stash list --pretty | List the stashed entries with more information. |
git stash apply [<stash>] | Restore the entry <stash> (the last one if <stash> is not present). The entry is kept among the stashed entries. |
git stash apply --index [<stash>] | Try to reinstate not only the working tree’s changes, but also the index’s ones. |
git stash drop [<stash>] | Remove the stash entry <stash> (the last one if <stash> is not present). |
git stash pop [--index] [<stash>] | Apply and remove the stash entry <stash> (the last one if <stash> is not present). |
git stash branch <branchname> [<stash>] | Create and check out a new branch <branchname> starting from the commit at which <stash> was created, apply the changes recorded in <stash> to the new working tree and index. |
git stash clear | Remove all stash entries. |
git reset’s man page | Reset current HEAD to the specified state. |
git reset <commit> | Reset the index entries for all paths to a previous commit
If no commit is specified, the current HEAD is used.
The local changes are not lost. |
git reset HEAD~ | Cancel the last commit. |
git reset <commit> <pathspec> | Reset the index <pathspec> entry to a previous commit
if no commit is specified, the current HEAD is used.
This means that git reset <pathspec> is the opposite of git add <pathspec>. |
git reset --soft <commit> | Do not touch the index file or the working tree. Only resets the head to <commit>, just like all modes do. |
git reset --mixed <commit> | Reset the index but not the working tree
this is the default. |
git reset --hard <commit> | Reset the index and the working tree. |
git reset --hard HEAD~2 | Delete the last two commits from the local repository. |
git restore’s man page | Restore working tree files. |
git restore <file>
git checkout <file>
git checkout -- <file> | Replace <file> in the working tree by its version in HEAD.
git checkout <file> will not work if a branch is named <file>, this will checkout that branch. |
git restore --staged <file> | Remove the file will from staging, its modifications in the workspace remain untouched. |
git restore --source <commit> <file> | Replace <file> in the working tree by its version in commit <commit>. |
git restore --source HEAD@{10.minutes.ago} <file>
git checkout HEAD@{10.minutes.ago} -- <file> | Replace <file> in the working tree by its HEAD version as it was 10 minutes ago. |
git restore -p <file>
git restore --patch <file>
git checkout -p -- <file>
git checkout --patch -- <file> | Interactively select hunks in the difference between the restore source and the restore location. |
git push’s man page | Update remote refs along with associated objects. |
git push <remotename> <branchname> | Push commits made on a local branch to a remote repository in the branch of same name. |
git push https://username:password@mygithost.com/file.git | Specify the credentials on the command line. |
git push --all | Push all branches. |
git push -u origin <branchname>
git push --set-upstream origin <branchname> | For every branch that is up to date or successfully pushed, add upstream (tracking) reference.
This is to be used when a branch has been created locally and does not exist in the remote repository. |
git push --force
git push -f | Do not check that the remote ref is an ancestor of the local ref.
Do not use, use --force-with-lease instead. |
git push --force-with-lease | Only allow to force-push if no-one else has pushed changes up to the remote in the interim. |
git push --mirror | All refs under refs/ (which includes but is not limited to refs/heads/, refs/remotes/, and refs/tags/) are mirrored to the remote repository. Newly created local refs are pushed to the remote end, locally updated refs are force updated on the remote end, and deleted refs are removed from the remote end. |
git push --dry-run
git push -n | Do everything except actually send the updates. |
git push --signed | GPG-sign the push request. |
git push --tags | All refs under refs/tags are pushed, in addition to refspecs explicitly listed on the command line. |
git branch’s man page | List, create, or delete branches. |
git branch --show-current | Print the name of the current branch. |
git branch <new branch> | Create a new branch (but does not switch to it). |
git branch <new branch> <commit> | Create a new branch from a given commit. |
git branch
git branch -l
git branch --list | List the local branches, the current one is prefixed with *. |
git branch --column | Display branch listing in columns.
Can be set as default with the configuration variables column.branch or column.ui. |
git branch --sort=<key> | Sort based on the key given.
Prefix - to sort in descending order of the value.
The default sort can be defined with the configuration variable branch.sort. |
git branch -v
git branch --verbose | List the local branches, indicating sha1 and commit subject line for each head, and relationship to upstream branch (if any). |
git branch -vv | The same with path of the linked worktree (if any) and the name of the upstream branch. |
git branch -a
git branch --all | List the local and remote branches. |
git branch --contains <commit> | Only list branches which contain the specified commit. |
git branch --no-contains <commit> | Only list branches which do not contain the specified commit. |
git branch -m <new name>
git branch --move <new name> | Rename the current branch, with its config and reflog. |
git branch -m <new name> -f
git branch --move <new name> --force
git branch -M <new name> | Rename the current branch, with its config and reflog, even if a branch <new name> already exists. |
git branch -c <name>
git branch --copy <name> | Copy the current branch, with its config and reflog. |
git branch -c <name> -f
git branch --copy <name> --force
git branch -C <name> | Copy the current branch, with its config and reflog, even if a branch <name> already exists. |
git switch’s man page | Switch branches. |
git checkout’s man page | Switch branches or restore working tree files. |
git checkout -q
git checkout --quiet | Quiet, suppress feedback messages. |
git checkout --progress | Enable progress reporting even if not attached to a terminal. |
git switch <branch>
git checkout <branch> | Switch to another branch. |
git switch -
git checkout - | Switch back to the previous branch. |
git checkout -f
git checkout --force | When switching branches, proceed even if the index or the working tree differs from HEAD, and even if there are untracked files in the way. This is used to throw away local changes and any untracked files or directories that are in the way. |
git switch -c <branch>
git switch --create <branch>
git checkout -b <branch> | Create a new branch (while leaving the working tree unchanged) and check it out. |
git switch -C <branch>
git switch --force-create <branch>
git checkout -B <branch> | The same except that if <branch> already exists, it is reset to the current head. |
git switch -c <branch> <starting point>
git switch --create <branch> <starting point>
git checkout -b <branch> <starting point> | Create a new branch from a starting point and check it out. |
git switch -C <branch> <starting point>
git switch --force-create <branch> <starting point>
git checkout -B <branch> <starting point> | The same except that if <branch> already exists, it is reset to <starting point>. |
git switch -d <commit>
git switch --detach <commit>
git checkout --detach <commit> | Switch to a commit for inspection and discardable experiments. (Just do something such as git switch main to leave the detached head state.) |
git branch -d <branch>
git branch --delete <branch> | Delete a local branch. The branch must be fully merged in its upstream branch. |
git branch -d -f <branch>
git branch --delete --force <branch>
git branch -D <branch> | Delete a local branch even if it has not been merged. |
git push origin --delete <branch> | Delete a branch in the remote repository. |
git merge’s man page | Join two or more development histories together. |
git merge <branch> | Merge a branch in the workspace. |
git merge <branch> --no-commit --no-ff | Merge a branch in the workspace without committing. |
git add <file1> <file2> <file3>
git merge --continue |
| After a conflict resolution, add the fixed files to the index and continue the merge. |
git merge --abort | Cancel the current ongoing merge (if there was a conflict or with the --no-commit flag). |
git merge --squash | Update the working tree and index by merging the branch, but the commit is not performed (the commit will have to be done later). This can be used to merge one or several branches in a single commit. |
git merge -s ours
git merge --strategy=ours | Create a merge that keeps the current branch head (i.e. it ignores all the changes done on the other branches). |
git merge --allow-unrelated-histories | Allow merging histories of two projects that started their lives independently. |
git merge -m <msg> | Define the message of the merge commit. |
git cherry-pick’s man page | Apply the changes introduced by some existing commits. |
git cherry-pick <commit> | Cherry pick a commit and commit it. |
git cherry-pick <commit> -m 1
git cherry-pick <commit> --mainline 1 | Use to cherry pick a merge commit, -m 1 indicates to replay the change relative to the first parent. |
git cherry-pick <commit> -n
git cherry-pick <commit> --no-commit | Cherry pick a commit, but does not commit it. |
git mergetool’s man page | Run merge conflict resolution tools to resolve merge conflicts. |
git mergetool | Perform merge conflict resolution with a tool. |
git mergetool --tool-help | List the supported merge tools, indicating which ones are available. |
git checkout --patch <commit> . | Does not change the current branch.
Bring and manually accept the files of <commit> in the index. |
git tag’s man page | Create, list, delete or verify a tag object signed with GPG. |
git tag
git tag -l
git tag --list | List the existing tags. |
git tag -l <wildcard>
git tag --list <wildcard> | List the existing tags matching a wildcard, e.g.:
git tag --list "*.RELEASE" |
git tag --contains <commit> | Only list tags which contain the specified commit. |
git tag --no-contains <commit> | Only list tags which do not contain the specified commit. |
git tag -a <tagname> -m <tagcomment> | Create an annotated tag. |
git tag <tagname> | Create a lightweight tag. |
git tag -a <tagname> <commitchecksum> | Create a tag corresponding to a past commit. |
git push origin <tagname> | Push a tag on the remote. |
git push origin --tags | Push all tags on the remote. |
git tag -d <tagname> | Delete a tag locally. |
git push origin :refs/tags/<tagname>
git push origin --delete <tagname> | Delete a tag on the remote. |
git show -d <tagname> | Display who and when a tag was created. |
git config’s man page | Get and set repository or global options.
When reading, the values are read from the system, global, and repository local configuration files by default, and options --system, --global, --local, --worktree and --file <filename> can be used to tell the command to read from only that location.
When writing, the new value is written to the repository local configuration file by default, and options --system, --global, --worktree, --file <filename> can be used to tell the command to write to that location (we can use --local but that is the default). |
git config get user.name
old syntax:
git config --get user.name | Display the value of user.name. |
git config get --all user.name
old syntax:
git config --get-all user.name | Display all the values of user.name. |
git config get --all --show-origin user.name
old syntax:
git config --get-all --show-origin user.name | Display all the values of user.name with their origin. |
git config list
old syntax:
git config -l
git config --list | List all variables set in config file with their values. |
old syntax:
git config --global --list | Display the global configuration. |
git config --show-origin | Augment the output of all queried config options with the origin type and the actual origin. |
git config --show-scope | Augment the output of all queried config options with the scope of that value. |
git config -l --show-origin | List all variables set in config file with, their values, and the files in which they are defined. |
git config --global --edit | Open an editor to edit the global configuration file. |
old syntax:
git config --global user.name "John Doe"
git config set --global user.name "John Doe" | Set the name in the global configuration file. |
git config set --global user.email johndoe@example.com
old syntax:
git config --global user.email johndoe@example.com | Set the email in the global configuration file. |
git config set --system user.email johndoe@example.com
old syntax:
git config --system user.email johndoe@example.com | Set the email in the system-wide configuration file. |
git config set user.name "John Doe"
git config set --local user.name "John Doe"
old syntax:
git config user.name "John Doe"
git config --local user.name "John Doe" | Set the name in the local repository configuration file. |
git config unset <name>
git config unset --local <name>
old syntax:
git config --unset <name>
git config --local --unset <name> | Remove the line matching the key <name> from the configuration file. |
old syntax:
git config --remove-section <name> | Remove the section <name> from the configuration file. |
old syntax:
git config --replace-all | Default behaviour is to replace at most one line. This replaces all lines matching the key. |
old syntax:
git config --add | Adds a new line to the option without altering any existing values. |
git config --rename-section <old-name> <new-name> | Rename the section <old-name> into <new-name>. |
git config --global alias.ac "commit -am" | Define an alias. The alias can be used as git ac "Fixed my bug". |
git config --global alias.ac "!myscript.sh" | Define an alias of a shell command. |
The