Git Cheat Sheet

Git is the open source distributed version control system that facilitates GitHub activities on your PC. Browse summary of commonly used Git command line instructions:

Installing GIT

//GitHub for Windows

//GitHub for Mac

  * NOTE:: Git distributions for Linux and POSIX systems are
  * available on the official Git SCM web site.

//Git for All Platforms

Configure Tooling

// To Sets the name you want attached to your commit transactions
$ git config --global "[name]"

//Sets the email you want attached to your commit transactions
$ git config --global "[email address]"

//Enables helpful colorization of command line output
$ git config --global color.ui auto

Create Repositories

//Creates a new local repository with the specified name
$ git init [project-name]

//Downloads a project and its entire version history
$ git clone [url]

Refactor Filenames

//Deletes the file from the working directory and stages the deletion
$ git rm [file]

//Removes the file from version control but preserves the file locally
$ git rm --cached [file]

//Changes the file name and prepares it for commit
$ git mv [file-original] [file-renamed]

Save Fragments

//Temporarily stores all modified tracked files
$ git stash

//Restores the most recently stashed files
$ git stash pop

//Lists all stashed change sets
$ git stash list

//Discards the most recently stashed changeset
$ git stash drop

Synchronize Changes

//Downloads all history from the repository bookmark
$ git fetch [bookmark]

//Combines bookmark’s branch into current local branch
$ git merge [bookmark]/[branch]

//Uploads all local branch commits to GitHub
$ git push [alias] [branch]
$ git push origin master

//Downloads bookmark history and incorporates changes
$ git pull [alias] [branch] 
$ git pull origin master

Make Changes

//Lists all new or modified files to be committed
$ git status

//Shows file differences not yet staged
$ git diff

//Snapshots the file in preparation for versioning
$ git add [file]

//Shows file differences between staging and the last file version
$ git diff --staged

//Unstages the file, but preserve its contents
$ git reset [file]

//Records file snapshots permanently in version history
$ git commit -m "[descriptive message]"

Group Changes

//Lists all local branches in the current repository
$ git branch

//Creates a new branch
$ git branch [branch-name]

//Switches to the specified branch and updates the working directory
$ git checkout [branch-name]

//Combines the specified branch’s history into the current branch
$ git merge [branch]

//Deletes the specified branch
$ git branch -d [branch-name]

//Hard Deletes the specified branch - Force Delete the branch
$ git branch -D [branch-name]

//Delete Remote branch
$ git push origin --delete [branch-name]

Review History

//Lists version history for the current branch
$ git log

//Lists version history for a file, including renames
$ git log --follow [file]

//Shows content differences between two branches
$ git diff [first-branch]...[second-branch]

//Shows content differences between two commit
$ git diff [first-commit]...[second-commit]

//Outputs metadata and content changes of the specified commit
$ git show [commit]

Redo Commits

//Undoes all commits after [commit] , preserving changes locally
$ git reset [commit]

//Discards all history and changes back to the specified commit
$ git reset --hard [commit]

//Discards all history and changes back to the specified branch
$ git reset --hard [branch]

//Discard all history and change back to the remote branch
$ git reset --hard origin/[branch]