This page looks best with JavaScript enabled

git.cheatsheet

 ·  ☕ 3 min read

#-#
#-# Configuration
#-#

Define the author name to be used for all commits by the current user.

git config –global user.name

Define the author email to be used for all commits by the current user.

git config –global user.email

Create shortcut for a Git command.

E.g. alias.glog “log –graph –oneline” will set “git glog” equivalent to “git log –graph –oneline”

git config –global alias.

Set text editor used by commands for all users on the machine.

The arg should be the command that launches the desired editor (ex. vim).

git config –system core.editor

Open the global configuration file in a text editor for manual editing.

git config –global –edit

Enable helpful colorization of command line output

git config –global color.ui auto

List all configured properties

git config –list

#-#
#-# Command line
#-#

#-# Get and create repositories

Command Description


git clone Clone repo located at onto the local machine.
git init Create empty Git repo in specified directory.

#-# Basic snapshotting

Command Description


git status Show changed files in your working directory.
git diff Show changes to tracked files.
git diff –cached Show staged changes.
git add . Stage all changes to the next commit.
git add Stage changes in a file to the next commit.
git commit -am ‘’ Record all local changes in tracked files in version history.
git commit -m ‘’ Record staged changes permanently in version history.
git commit –amend Combine the staged changes with the last commit.

#-# Reset & Revert

Command Description


git checkout HEAD Discard local changes in .
git revert Revert a commit.
git reset –hard HEAD Discard all local changes in your working directory.
git reset –hard Reset HEAD to and discard all changes since.
git reset Reset HEAD to and preserve all changes as unstaged changes.
git reset –keep Reset HEAD to and preserve uncommitted local changes.
git rm Remove file from staging area and working directory.
git rm –cached Remove file from staging area.
git mv Move or rename a file. The changes will be staged.

#-# Remote

Command Description


git remote update Refresh list of remotes.
git remote -v List all currently configured remotes.
git remote show Display information about remote.
git remote add Add a new remote, named .
git fetch Download all changes from remote, don’t integrate into HEAD.
git pull Download changes and merge to HEAD.
git push Publish local changes.
git push : Delete a branch on the remote.
git push –tags Publish tags.

#-# Braches & Tags

Command Description


git branch List local branches.
git branch -a List both local and remote branches.
git branch -r List remote branches.
git checkout Switch to the specified branch and update working directory.
git branch Create new branch based on current HEAD.
git branch -d Delete local branch.
git tag Mark the current commit with a tag.

#-# Merge & Rebase

Command Description


git merge Merge into your current HEAD.
git rebase Rebase your HEAD onto .
git rebase –abort Abort a rebase.
git rebase –continue Continue a rebase after resolving conflicts.
git mergetool Use configured merge tool to resolve conflicts.

#-# Stash

Command Description


git stash Temporarily store all modified tracked files.
git stash save [msg] Same as above but naming the stash entry.
git stash pop Restore most recently stashed files.
git stash list List all stashed changes.
git stash drop Discard most recently stashed changeset.

#-# Review history

Command Description


git log Show all commits, starting with most recent.
git log Show changes over time for a file.
git log –follow List version history for a file, including renames.
git blame Show changes for a file with time and author.

Share on

Nicolas Guinet
Nicolas Guinet
Consultant .Net, C, C++, Python, Go. Full Stack Html/Css/Js/Node. I like to experiment new trends everyday. IA/ML player focused on scientific topics.