init
Create
Create an empty Git repository or reinitialize an existing one
Usage:
git init
Create an empty Git repository or reinitialize an existing one
git init --template=[template-directory]
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
Clone target repository
git clone -b [branch-name] ssh://user@domain.com/repo.git
Clone a repository with branch-name checked out
git clone ssh://user@domain.com/repo.git --depth=[number]
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
Adds url as submodule
git submodule init
Initializes local config file
git submodule update
Fetch all data from submodule
git submodule update --init --recursive
Updates local submodule
git submodule sync --recursive
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]
Adds given file to stage area
git add folder/*
Adds all files within given folder
git add *.extension
Adds all extension files to stage area
git add --patch [source]
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
Changed files on your working directory
git status -s
Give the output in the short-format
git status -b
Show the branch and tracking info even in short-format
diff
Changes
Shows file differences not yet staged
Usage:
git diff
Show changes all changes between the working tree and the index
git diff [source]
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]
Use the given message as the commit message. If multiple -m usage are given, their values are concatenated as separate paragraphs
git commit --all
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
Updates the last commit without creating a new commit
git commit --squash
Create a single commit on top of the current branch
stash
Changes
Stash and restore incomplete changes
Usage:
git stash list
Shows all your stashes
git stash save [stash message]
Saves your local modifications to a new stash entry
git stash apply stash@{index}
Applies the stash in index
git stash pop stash@{index}
Applies the stash in index and removes it from stash list
git stash drop stash@{index}
Removes the index from stash list without applying
git stash clear
Clears the stash list
mv
Changes
Move or rename a file or a directory
Usage:
git mv [source] [destination]
Moves or renames source
git mv -f [source] [destination]
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
Lists all tags
git tag [tag-name]
Marks the current commit with a [tag-name]
git tag [tag-name] [commit-hash]
Marks the [commit-hash] commit with a [tag-name]
git tag -a [tag-name]
Marks the current commit with an annotated [tag-name] such as v1.4
git tag --delete [tag-name]
Delete existing tags with the given [tag-name]
branch
Branch
List, rename, create, or delete branches
Usage:
git branch
Lists tracked branches
git branch -a
List both remote-tracking branches and local branches
git branch [branch-name]
Creates a new branch from HEAD called [branch-name]
git branch -m [branch-name]
Rename current branch to [branch-name]
git branch -d [branch-name]
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]
Switches to a branch called [branch-name]
git switch -c [branch-name]
Creates and switches to a new branch from HEAD called [branch-name]
git switch -c [branch-name] [start-point]
Creates and switches to a new branch from [start-point] called [branch-name]
git switch --orphan
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]
Switch to [branch-name] or restore working tree files
git checkout -b [branch-name]
Create and switch to [branch-name] or restore working tree files
git checkout --track [origin/branch-name]
Checkout and track a remote branch
git checkout .
Discard all tracked local changes in HEAD
git checkout HEAD [source]
Resets tracked [source] file/folder
fetch
Update
Downloads all history from the remote repository
Usage:
git fetch --all
Fetch all remotes
git fetch --prune
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
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
Update remote refs along with associated objects
git push --force
Overwrite remote refs with your local branch
git push --force-with-lease
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]
Merges a branch to your current HEAD
rebase
Patch
Rebase your current HEAD onto target branch
Usage:
git rebase [branch-name]
Rebase your current HEAD onto branch-name
git rebase --interactive
Makes a list of the commits which are about to be rebased. User can edit that list before rebasing.
git rebase --continue
Continue a rebase after resolving conflicts
git rebase --abort
Abort a rebase
cherry-pick
Patch
Apply the changes from a different commit to your current HEAD
Usage:
git cherry-pick [commit]
Pick and apply changes from commit hash to your current HEAD
reset
Undo
Undoes all commits after [commit], preserving changes locally
Usage:
git reset
Resets the index entries for all paths to their state
git reset --soft
Does not touch the index file or the working tree at all
git reset --mixed
Resets the index but not the working tree and reports what has not been updated
git reset --hard
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
Revert to the latest commit
git revert [commit-hash]
Revert to the [commit-hash] commit
git revert -n [commit-hash]
Revert to the [commit-hash] commit but do not commit
clean
Undo
Shows untracked files about to be removed
Usage:
git clean -n
Shows untracked files about to be removed
git clean -f
Removes all untracked files
git clean -x
Removes all ignored files
git clean -i
Runs clean command with interactive menu
log
History
Lists version history for the current branch
Usage:
git log
Show all commits
git log --graph
Shows all commits as graph
git log -p [source]
Show changes to file
config
Administration
Get and set repository or global usage
Usage:
git config -e
Edit repository config file
git config --global -e
Edit global config file
git config --global user.name 'Your Name'
Define your user name in global settings
git config --global user.email you@mail.com
Define your mail in global settings
gc
Administration
Cleanup unnecessary files and optimize the local repository
Usage:
git gc
Runs a garbage collection for your local repository
git gc --aggressive
Runs gc more aggressively to optimize your local repository
prune
Administration
Prune all unreachable objects from the object database
Usage:
git prune
Removes objects that are no longer pointed to any object in reachable branch
git prune -n
Do not remove anything; just report what it would remove
git prune --progress
Shows prune progress
bisect
Debug
Use binary search to find the commit that introduced a bug
Usage:
git bisect start
Start up the git bisect wizard
git bisect good [commit]
Let the git bisect wizard know of a good commit
git bisect bad [commit]
Let the git bisect wizard know of a bad commit
git bisect reset
End your git bisect wizard
blame
Debug
Display author metadata attached to specific committed lines in a file
Usage:
git blame [source]
Show each author worked on the source including date, time and line numbers
git blame -L x,y [source]
Restrict the output of source between x and y lines
git blame -e [source]
Show author email address instead of username
git blame -w [source]
Ignore whitespace changes