Places
git’s man pageGit.
git version’s man pageDisplay version information about Git.
git -v
git --version
git version
Print the version of Git.
git --attr-source=<tree-ish>Read gitattributes from <tree-ish> instead of the worktree.

git init’s man pageCreate an empty local repository.
git init -q
git init --quiet
Only print error and warning messages; all other output will be suppressed.
mkdir projet.git
cd projet.git
git --bare init
Create an empty server repository.

git clone’s man pageClone 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-branchClone 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-submodulesClone 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 remote’s man pageList the upstream and downstream repositories.
git remoteDisplay the list of existing remotes.
git remote -vThe same more verbose and with remote URL after name.
git remote add <remotename> <url>Add a remote named <remotename> for the repository at <url>.
git remote remove <remotename>
git remote rm <remotename>
Remove the remote named <remotename>. All remote-tracking branches and configuration settings for the remote are removed.
git config --get remote.origin.urlDisplay the URL the local repository has been cloned from.
git remote -v rm originRemove the tracking of the remote "origin".

git ls-files’s man pageList files which are in the workspace or in the index.
git ls-files -mList modified files.
git ls-files -oList files which are in the workspace and not in the index.

git add’s man pageAdd file contents to the index.
git add <file>Update <file> in the index using the current content found in the working tree.
git add .Update the content of the current directory in the index.
git add -i
git add --interactive
Add modified contents in the working tree interactively to the index.
Optional path arguments may be supplied to limit operation to a subset of the working tree.
git stage’s man pagegit stage is a synonym of git add.

git rm’s man pageRemove files from the working tree and from the index.
git rm <file>Remove <file> from the index, or from the working tree and the index.

git status’s man pageDisplay
  • paths that have differences between the index file and the current HEAD commit
  • paths that have differences between the working tree and the index file, and
  • paths in the working tree that are not tracked by Git

git commit’s man pageRecord changes to the repository.
git commit -m <msg>Store the current contents of the index in a new commit along with message <msg>.
git commit -a
git commit --all
Automatically stage files that have been modified and deleted, but new files you have not told Git about are not affected.
git commit -o
git commit --only
Make a commit by taking the updated working tree contents of the paths specified on the command line, disregarding any contents that have been staged for other paths.
(This is the default of git commit if any paths are given on the command line. So, in this case the -o is useless.)
git commit --amendReplace the tip of the current branch by creating a new commit.
git commit --amend --no-editAmend a commit without changing its commit message.
git commit --amend -m "an updated commit message"Change the commit message.
git commit --amend --reset-authorDeclare that the authorship of the new commit belongs to the committer.
git commit --amend --author="John <John@foo.bar>"Declare that the authorship of the new commit belongs to the specified name/email.
git commit -S
git commit --gpg-sign
GPG-sign commits.

git notes’s man pageAdd or inspect object notes
git notes add -m <message>Add notes to the HEAD object.
git notes add -f -m <message>Overwrite notes of the HEAD object.
git notes append -m <message>Append the message to the notes of the HEAD object. (If it has no notes, this will create them.)

git diff’s man pageDisplay the differences between the workspace and the index.
git diff --cachedDisplay the differences between the index and the local repository.
git diff origin/mainDisplay the differences between the work space and the main branch on the upstream repository.
git diff --name-onlyDisplay only the filenames.
git diff <commit 1> <commit 2> <file>Compare two revisions of a file.
git diff <branch 1> <branch 2> -- <file>Compare two versions of a file in different branches,
git diff master remotes/origin/hisbranch -- pom.xml
git diff <branch> -- <file>Compare the current version of a file with one in a different branch.
git diff <commit 1>:<file 1> <commit 2>:<file 2>Compare two different files in two different revisions.
git diff --word-diffShow a word diff.
git diff -U<n>
git diff --unified=<n>
Generate diffs with <n> lines of context instead of the usual three.

git apply’s man pageApply a patch.

git log’s man pageShow commit logs.
git log --allPretend as if all the refs in refs/, along with HEAD, are listed on the command line as <commit>.
git log --full-historyDo 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-historyDoes not prune some history.
git log --full-history --simplify-mergesSame 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-grepLimit 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-regexpConsider 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-regexLook 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-allWhen -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.csvDump the authors and dates of the commits in a file.
git log --name-onlyShow only names of changed files.
git log --name-statusShow only names and status of changed files.
git log --abbrev-commitSInstead of showing the full 40-byte hexadecimal commit object name, show a prefix that names the object uniquely.
git log --onelineShorthand 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=longPrint out the full ref names of any commits that are shown.
git log decorate=autoIf 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 --statIndicate the modified files with a graph of the stats of the changes.
git log --shortstatIndicate 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 --graphDraw a text-based graphical representation.
git log --reverseOutput the commits chosen to be shown in reverse order.
git whatchanged’s man pageShow logs with difference each commit introduces.
git whatchangedList the last commits: hash, author, date, and list of impacted files.
git shortlog’s man pageSummarize 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 -nseList of authors with their emails sorted by number of commits.

git show’s man pageShow changes between commits, commit and working tree…
git show <commit>Show the log message and textual diff.
git show --name-only <commit>Show the log message and the name of the modified files.
git show --name-status <commit>Show the log message and the name and status of the modified files.
git show <commit>:<file>Display a given version of a file.

git blame’s man pageShow what revision and author last modified each line of a file.
git blame <file>Annotate each line of the file with information from the revision which last modified the line.
git blame -L <start>,<end>
git blame -L :<funcname>
Annotate only the line range given by <start>,<end>, or by the function name regex <funcname>. May be specified multiple times. Overlapping ranges are allowed.
git blame -MDetect moved or copied lines within a file.
git blame -CDetect lines moved or copied from other files that were modified in the same commit.
When this option is given twice (-C -C), the command additionally looks for copies from other files in the commit that creates the file.
When this option is given three times(-C -C -C), the command additionally looks for copies from other files in any commit.
git blame -wIgnore whitespaces.
git blame -f
git blame --show-name
Show the filename in the original commit (by default the filename is shown if there is any line that came from a file with a different name, due to rename detection).
git blame --date=format:%Y%dDefine a format for the dates.
git blame --show-emailShow the author email instead of author name.
git blame -lindicate all (40) characters of the revision.
git annotate’s man pageAnnotate file lines with commit information.
git annotate <file>Same feature as git blame but the output is slightly different.

git reflog’s man pageManage reflog information
git reflog
git reflog show
Show the log of HEAD.
git reflog <ref>
git reflog show <ref>
Show the log of the reference <ref>.

git stash’s man pageStash 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-indexAll 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.txtStash 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 listList the stashed entries.
git stash list --prettyList 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 clearRemove all stash entries.

git worktree’s man pageManage multiple working trees.
git worktree add <path> <branchname>Create a worktree in directory <path> for branch <branchname>.
git worktree listList details of each working tree. The main working tree is listed first.
git worktree remove <worktree>Remove a worktree. The main working tree cannot be removed.

git reset’s man pageReset 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~2Delete the last two commits from the local repository.
git restore’s man pageRestore 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 sparse-checkout’s man pageReduce your working tree to a subset of tracked files
git sparse-checkout set MY/DIR1 SUB/DIR2Enable the necessary sparse-checkout config settings (core.sparseCheckout, core.sparseCheckoutCone, and index.sparse) if they are not already set to the desired values, populate the sparse-checkout file from the list of arguments following the set subcommand, and update the working directory to match.
git sparse-checkout add MY/DIR1 SUB/DIR2Update the sparse-checkout file to include additional directories (in cone mode) or patterns (in non-cone mode).
Example:
REPO=https://github.com/danascheider/tessitura-front-end.git
DIR=features
git clone --filter=blob:none --no-checkout --depth 1 --sparse $REPO
cd `basename -s .git $REPO`
git config set --global --append safe.directory `pwd`
git sparse-checkout set $DIR
git checkout



git config unset --global --value `pwd` safe.directory
cd ..
rm -rf `basename -s .git $REPO`

git revert’s man pageRevert some existing commits.
git revert <commit1> <commit2> …Revert some commits (a revert is a staged commit reverting a given past commit). If we indicate several commits on the command line, there will be one revert per indicated commit.

git replace’s man pageCreate, list, delete refs to replace objects.

git fetch’s man pageDownload objects and refs from another repository.
git fetchDownload objects and refs from upstream repository into local repository.
The names of refs that are fetched, together with the object names they point at, are written to .git/FETCH_HEAD.
git fetch --allFetch all remotes.
git fetch --append
git fetch -a
Append ref names and object names of fetched refs to the existing contents of .git/FETCH_HEAD. Without this option old data in .git/FETCH_HEAD will be overwritten.
git fetch --depth=<depth>Limit fetching to the specified number of commits from the tip of each remote branch history.
Tags for the deepened commits are not fetched.
git fetch --deepen=<depth>Similar to --depth, except it specifies the number of commits from the current shallow boundary instead of from the tip of each remote branch history.
git fetch --unshallowIf the source repository is complete, convert a shallow repository to a complete one, removing all the limitations imposed by shallow repositories.
If the source repository is shallow, fetch as much as possible so that the current repository has the same history as the source repository.
git fetch origin dev:devUpdate the dev branch to be the head of the remote dev branch.
git fetch -p
git fetch --prune
Before fetching, remove any remote-tracking references that no longer exist on the remote.

git pull’s man pageFetch from and integrate with another repository or a local branch.
git pullIncorporate changes of the remote repository into the current branch, it is the same as
  • git fetch scoped to the local branch that HEAD is pointed at
  • followed by git merge FETCH_HEAD.
git pull --rebasePerform a rebase instead of a merge.
git pull -p
git pull --prune
Before fetching, remove any remote-tracking references that no longer exist on the remote.

git push’s man pageUpdate 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.gitSpecify the credentials on the command line.
git push --allPush 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-leaseOnly allow to force-push if no-one else has pushed changes up to the remote in the interim.
git push --mirrorAll 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 --signedGPG-sign the push request.
git push --tagsAll refs under refs/tags are pushed, in addition to refspecs explicitly listed on the command line.

git clean’s man pageDelete untracked files from the working tree.
git clean -dRecurse into untracked directories.
git clean -e <pattern>
git clean --exclude=<pattern>
Exclude the files/directories matching <pattern> in addition to the standard ignore rules.
git clean -xDon’t use the standard ignore rules, but still use the ignore rules given with -e options from the command line. This allows removing all untracked files, including build products.
git clean -XRemove only files ignored by Git. This may be useful to rebuild everything from scratch, but keep manually created files.
git clean -f
git clean --force
Clean file with no interaction. Perform the deletion if the Git configuration variable clean.requireForce is not set to false.
Untracked nested git repositories (directories with a .git subdirectory) are ignored unless a second -f is given.
git clean -i
git clean --interactive
Show what would be done and clean files interactively.
git clean -n
git clean --dry-run
Does not remove anything, list the files and directories that would be removed.

git branch’s man pageList, create, or delete branches.
git branch --show-currentPrint 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 --columnDisplay 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 -vvThe 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 pageSwitch branches.
git checkout’s man pageSwitch branches or restore working tree files.
git checkout -q
git checkout --quiet
Quiet, suppress feedback messages.
git checkout --progressEnable 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 pageJoin two or more development histories together.
git merge <branch>Merge a branch in the workspace.
git merge <branch> --no-commit --no-ffMerge 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 --abortCancel the current ongoing merge (if there was a conflict or with the --no-commit flag).
git merge --squashUpdate 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-historiesAllow 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 pageApply 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 pageRun merge conflict resolution tools to resolve merge conflicts.
git mergetoolPerform merge conflict resolution with a tool.
git mergetool --tool-helpList 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 pageCreate, 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 --tagsPush 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 bisect’s man pageUse binary search to find the commit that introduced a bug.

git show-ref’s man pageList the references in the local repository and their associated commits.

git hash-object’s man pageCompute object ID and optionally create an object from a file.
git hash-object <file>Compute the file hash.
git hash-object --stdinRead data to hash from standard input.
git hash-object -wActually write the object into the object database.
git hash-object -t <type>Specify the type (default: "blob").

git cat-file’s man pageProvide content or type and size information for repository objects.
git cat-file -t 47281c0d4fae6480a95aced8887244544feba9c5Display the type of a repository object.
git cat-file -p 47281c0d4fae6480a95aced8887244544feba9c5Display the content (pretty printed) of a repository object.

git count-objects’s man pageDisplay the number of unpacked object files and disk space consumed by them.

git grep’s man pagePrint lines matching a pattern.

git update-ref’s man pageUpdate the object name stored in a ref safely.
git update-ref -d <ref>Delete reference <ref> in the local repository.

git gc’s man pageCompress file revision and remove unreachable objects.

git fsck’s man pageVerifies the connectivity and validity of the objects in the database.

git maintenance’s man pageRun tasks to optimise Git repository data.
git maintenance registerInitialize Git config values so any scheduled maintenance will start running on this repository.
git maintenance unregisterRemove the current repository from background maintenance.

git submodule’s man pageInitialize, update or inspect submodules.
git submodule add https://github.com/chaconinc/DbConnectorAdd an existing Git repository as a submodule.

git config’s man pageGet 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.
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-originAugment the output of all queried config options with the origin type and the actual origin.
git config --show-scopeAugment the output of all queried config options with the scope of that value.
git config -l --show-originList all variables set in config file with, their values, and the files in which they are defined.
git config --global --editOpen 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 include and includeIf sections allow to include config directives from another source.

It is possible to ignore files/directories in a given directory by listing them in the .gitignore file of that directory.

In order to commit an empty directory, create a .gitkeep file in it. This is not defined by Git, but it is a common usage.

To remove the last commit locally and on the remote repository (nobody should have pulled meanwhile)
#> git reset --hard HEAD^
#> git push -f

git rebase’s man pageReapply commits on top of another base tip.
git rebase --interactive
git rebase -i
Start an interactive rebase: the list of commits is generated and the user can edit them.
git rebase --continueRestart the rebasing process after having resolved a merge conflict.
git rebase --abortAbort the rebase operation and reset HEAD to the original branch.
git rebase --quitAbort the rebase operation but HEAD is not reset back to the original branch.
git rebase --update-refsAutomatically force-update any branches that point to commits that are being rebased.
git rebase --exec <cmd>
git rebase -x <cmd>
Append exec <cmd> after each line creating a commit in the final history.

git replay’s man pageReplay commits on a new base, works with bare repos too.

git rerere’s man pageReuse recorded resolution of conflicted merges.
Must be enabled by git config --global rerere.enabled true.
git merge and git commit automatically invoke git rerere, so there is no need to call it directly.

git commit --fixup=<commit>Create a fixup! commit which changes the content of <commit> but leaves its log message untouched.
git commit --fixup=amend:<commit>Similar but create an amend! commit which also replaces the log message of <commit> with the log message of the amend! commit.
git commit --fixup=reword:<commit>
git commit --fixup=amend:<commit> --only
Create an amend! commit which replaces the log message of <commit> with its own log message but makes no changes to the content of <commit>.
git commit --squash=<commit>Construct a commit message for use with rebase --autosquash. The commit message subject line is taken from the specified commit with a prefix of squash!.
git rebase --autosquashWhen the commit log message begins with squash! …​ or fixup! …​ or amend! …​, and there is already a commit in the todo list that matches the same , automatically modify the todo list of rebase -i, so that the commit marked for squashing comes right after the commit to be modified, and change the action of the moved commit from pick to squash or fixup or fixup -C respectively.
A commit matches the if the commit subject matches, or if the refers to the commit’s hash. As a fall-back, partial matches of the commit subject work, too.

git credential’s man pageRetrieve and store user credentials
git credential fillretrieve the credentials
#> git credential fill << EOF
protocol=https
host=github.com
EOF
protocol=https
host=github.com
username=john
password=gho_DHaifTZE9NtPIZE3iShEit8qpzbtCi4I8boT
git credential rejectforget the credentials
#> git credential reject << EOF
protocol=https
host=github.com
EOF
git credential approverecord credentials (the OS will display a mesage for login in)
#> git credential fill << EOF
protocol=https
host=github.com
EOF
protocol=https
host=github.com
username=jane
password=gho_WnwWimkTLgqiKJZEFr48dABX1nPous670DKaUw

git column’s man pageDisplay data in columns.


Changing the author of old commits
Update a hierarchy of workspaces
find . -type d -name ".git" -execdir git pull -v \;

Script to mirror a repository in another (to be completed to support GitHub)
#!/bin/bash

source_repo="gitlab.com/lmazure_TestGroup"
source_project="secondtestproject"
target_repo="gitlab.com/lmazure_testmirroring"
target_project="secondtestprojectmirror"
git clone --mirror https://$source_repo/$source_project.git
cd $source_project.git
git show-ref | grep ' refs/merge-requests/' | cut -d' ' -f2 | xargs -n1 -r git update-ref -d # do not push merge-requests refs to GitLab, it will refuse them
git push --mirror https://$target_repo/$target_project.git
cd ..
rm -fr $project.git

Script to find the nearest version of a file ($1) compared to a local file ($2)
#!/bin/bash

file=$1
commits=$(git log -n 20 --format="%H" $1)
for commit in $commits
do
    echo "-------------------------"
    echo $commit
    git checkout --quiet $commit $1
    sdiff -s $1 $2 | wc -l
done
git checkout --quiet HEAD $1

Git on Windows
Git SVN
Fix a repository created by Eclipse
Git BASH on Windows
My configuration