init

Create

Create an empty Git repository or reinitialize an existing one

Usage:

git init
Copied

Create an empty Git repository or reinitialize an existing one

git init --template=[template-directory]
Copied

Create Git repository with template directory contents

clone

Create

Creates a local copy of a project that already exists remotely

Usage:

git clone ssh://user@domain.com/repo.git
Copied

Clone target repository

git clone -b [branch-name] ssh://user@domain.com/repo.git
Copied

Clone a repository with branch-name checked out

git clone ssh://user@domain.com/repo.git --depth=[number]
Copied

Clones target repository with history truncated to depth

submodule

Create

Initialize, update or inspect submodules

Usage:

git submodule add https://github.com/excalith/dev-cheats
Copied

Adds url as submodule

git submodule init
Copied

Initializes local config file

git submodule update
Copied

Fetch all data from submodule

git submodule update --init --recursive
Copied

Updates local submodule

git submodule sync --recursive
Copied

If submodule cannot be reached somehow, sync command will help you resync your config

add

Changes

Stages changes in the working tree

Usage:

git add [source]
Copied

Adds given file to stage area

git add folder/*
Copied

Adds all files within given folder

git add *.extension
Copied

Adds all extension files to stage area

git add --patch [source]
Copied

Interactively choose hunks of patch between the index and the work tree and add them to the index

status

Changes

Shows the status of changes as untracked, modified, or staged

Usage:

git status
Copied

Changed files on your working directory

git status -s
Copied

Give the output in the short-format

git status -b
Copied

Show the branch and tracking info even in short-format

diff

Changes

Shows file differences not yet staged

Usage:

git diff
Copied

Show changes all changes between the working tree and the index

git diff [source]
Copied

Show changes to a file between the working tree and the index

commit

Changes

Saves the snapshot to the project history

Usage:

git commit -m [message]
Copied

Use the given message as the commit message. If multiple -m usage are given, their values are concatenated as separate paragraphs

git commit --all
Copied

Tell the command to automatically stage files that have been modified and deleted, but new files you have not told Git about are not affected

git commit --amend
Copied

Updates the last commit without creating a new commit

git commit --squash
Copied

Create a single commit on top of the current branch

stash

Changes

Stash and restore incomplete changes

Usage:

git stash list
Copied

Shows all your stashes

git stash save [stash message]
Copied

Saves your local modifications to a new stash entry

git stash apply stash@{index}
Copied

Applies the stash in index

git stash pop stash@{index}
Copied

Applies the stash in index and removes it from stash list

git stash drop stash@{index}
Copied

Removes the index from stash list without applying

git stash clear
Copied

Clears the stash list

rm

Changes

Remove files from the index

Usage:

git rm [source]
Copied

Removes file from stage area

mv

Changes

Move or rename a file or a directory

Usage:

git mv [source] [destination]
Copied

Moves or renames source

git mv -f [source] [destination]
Copied

Forces to move or rename the source even if it exists in destination

tag

Changes

Marks the current commit with a tag

Usage:

git tag
Copied

Lists all tags

git tag [tag-name]
Copied

Marks the current commit with a [tag-name]

git tag [tag-name] [commit-hash]
Copied

Marks the [commit-hash] commit with a [tag-name]

git tag -a [tag-name]
Copied

Marks the current commit with an annotated [tag-name] such as v1.4

git tag --delete [tag-name]
Copied

Delete existing tags with the given [tag-name]

branch

Branch

List, rename, create, or delete branches

Usage:

git branch
Copied

Lists tracked branches

git branch -a
Copied

List both remote-tracking branches and local branches

git branch [branch-name]
Copied

Creates a new branch from HEAD called [branch-name]

git branch -m [branch-name]
Copied

Rename current branch to [branch-name]

git branch -d [branch-name]
Copied

Delete [branch-name]. The branch must be fully merged in its upstream branch, or in HEAD if no upstream was set with --track or --set-upstream

switch

Branch

Switch or create branches

Usage:

git switch [branch-name]
Copied

Switches to a branch called [branch-name]

git switch -c [branch-name]
Copied

Creates and switches to a new branch from HEAD called [branch-name]

git switch -c [branch-name] [start-point]
Copied

Creates and switches to a new branch from [start-point] called [branch-name]

git switch --orphan
Copied

Creates a new orphan branch called [branch-name] and removes all tracked files

checkout

Branch

Switch branches or restore working tree files

Usage:

git checkout [branch-name]
Copied

Switch to [branch-name] or restore working tree files

git checkout -b [branch-name]
Copied

Create and switch to [branch-name] or restore working tree files

git checkout --track [origin/branch-name]
Copied

Checkout and track a remote branch

git checkout .
Copied

Discard all tracked local changes in HEAD

git checkout HEAD [source]
Copied

Resets tracked [source] file/folder

fetch

Update

Downloads all history from the remote repository

Usage:

git fetch --all
Copied

Fetch all remotes

git fetch --prune
Copied

Before fetching, remove any remote-tracking references that no longer exist on the remote

pull

Update

Updates the local branch from its remote counterpart

Usage:

git pull
Copied

Fetch from and integrate with another repository or a local branch

push

Update

Uploads all local branch commits to its remote counterpart

Usage:

git push
Copied

Update remote refs along with associated objects

git push --force
Copied

Overwrite remote refs with your local branch

git push --force-with-lease
Copied

Prevents overwriting remote refs with your local branch

merge

Merge

Combines the specified branch’s history into the current branch

Usage:

git merge [branch-name]
Copied

Merges a branch to your current HEAD

rebase

Patch

Rebase your current HEAD onto target branch

Usage:

git rebase [branch-name]
Copied

Rebase your current HEAD onto branch-name

git rebase --interactive
Copied

Makes a list of the commits which are about to be rebased. User can edit that list before rebasing.

git rebase --continue
Copied

Continue a rebase after resolving conflicts

git rebase --abort
Copied

Abort a rebase

cherry-pick

Patch

Apply the changes from a different commit to your current HEAD

Usage:

git cherry-pick [commit]
Copied

Pick and apply changes from commit hash to your current HEAD

reset

Undo

Undoes all commits after [commit], preserving changes locally

Usage:

git reset
Copied

Resets the index entries for all paths to their state

git reset --soft
Copied

Does not touch the index file or the working tree at all

git reset --mixed
Copied

Resets the index but not the working tree and reports what has not been updated

git reset --hard
Copied

Resets the index and working tree. Any changes to tracked files in the working tree since commit are discarded

revert

Undo

Removes all changes made by commits from repository

Usage:

git revert HEAD
Copied

Revert to the latest commit

git revert [commit-hash]
Copied

Revert to the [commit-hash] commit

git revert -n [commit-hash]
Copied

Revert to the [commit-hash] commit but do not commit

clean

Undo

Shows untracked files about to be removed

Usage:

git clean -n
Copied

Shows untracked files about to be removed

git clean -f
Copied

Removes all untracked files

git clean -x
Copied

Removes all ignored files

git clean -i
Copied

Runs clean command with interactive menu

log

History

Lists version history for the current branch

Usage:

git log
Copied

Show all commits

git log --graph
Copied

Shows all commits as graph

git log -p [source]
Copied

Show changes to file

config

Administration

Get and set repository or global usage

Usage:

git config -e
Copied

Edit repository config file

git config --global -e
Copied

Edit global config file

git config --global user.name 'Your Name'
Copied

Define your user name in global settings

git config --global user.email you@mail.com
Copied

Define your mail in global settings

gc

Administration

Cleanup unnecessary files and optimize the local repository

Usage:

git gc
Copied

Runs a garbage collection for your local repository

git gc --aggressive
Copied

Runs gc more aggressively to optimize your local repository

prune

Administration

Prune all unreachable objects from the object database

Usage:

git prune
Copied

Removes objects that are no longer pointed to any object in reachable branch

git prune -n
Copied

Do not remove anything; just report what it would remove

git prune --progress
Copied

Shows prune progress

bisect

Debug

Use binary search to find the commit that introduced a bug

Usage:

git bisect start
Copied

Start up the git bisect wizard

git bisect good [commit]
Copied

Let the git bisect wizard know of a good commit

git bisect bad [commit]
Copied

Let the git bisect wizard know of a bad commit

git bisect reset
Copied

End your git bisect wizard

blame

Debug

Display author metadata attached to specific committed lines in a file

Usage:

git blame [source]
Copied

Show each author worked on the source including date, time and line numbers

git blame -L x,y [source]
Copied

Restrict the output of source between x and y lines

git blame -e [source]
Copied

Show author email address instead of username

git blame -w [source]
Copied

Ignore whitespace changes

Made with by excalith