Git Cheat Sheet

basics
command arg(s) description
git Lists git options and some common git commands
git --version Displays version information. As of this writing, the current version is 2.13
git add filespec Stages all changes in filespec for the next commit
git clone URL Create a local copy of the repository at URL
git commit [-a] -m YourComment Saves changes to local repository. -a stages, then commits
git config --global alias.co checkout Creates a Git aliases called co
git diff Show unstaged changes between your index and working directory
git diff HEAD Show difference between working directory and last commit
git help [command] Provides detailed information on [command]
git init directory Create an empty Git repository in directory.
git log [-p] [-#] Lists the commits made in reverse chronological order – most recent first
git mv filespec Rename filespec
git remote [-v] Lists all of your remote handles
git rm filespec Remove filespec
git show tag Display the data associated with a specific tag
git tag -a tagname -m your comment Create an annotated tag
branching
command arg(s) description
git branch Shows all of your branches
git branch --merged Displays branches that are already merged into the current branch
git branch --no-merged Displays branches that have not been merged into the current branch
git branch -v Displays the last commit on each branch
git checkout [-b] branchname Create and check out a new branch named branchname . Drop the -b flag to checkout an existing branch
git merge branch Merge branch into the current branch.
remote
command arg(s) description
git fetch remote [branch] Fetches a specific branch from the remote repository. Leave off branch to fetch all remote references.
git ls-remote Shows a full list of remote references
git pull remote Fetch the remote copy of current branch and immediately merge it into the local copy.
git push remote branch Push the branch to remote , along with necessary commits and objects. Creates named branch in the remote repository if it does not exist.
git push origin --delete remoteBranchName Deletes the remote branch remoteBranchName
git remote show Displays all remote branch names
un do
command arg(s) description
git clean -n Shows which files would be removed from working directory. Use the -f flag in place of the -n flag to execute the clean.
git reset file Remove file from the staging area, but leave the working directory unchanged. This unstages a file without overwriting any changes.
git revert commit Create new commit that undoes all of the changes made in commit , then apply it to the current branch.