Juicy lil' bytes

Essential Git Commands | a Cheat Sheet for Git Version Control

A reference sheet that includes the most commonly used Git commands.

Contents

Begin Version Control with Git

Create a Local Git Repository Track New Files Perform Initial Version Commit

Local Development with Git

State Reporting View File Modifications Prepare for Next Commit Commit Modified Version Branches and Merging Commit Modification

Viewing Commit History

Git Logs

Working with Remote Repositories

Tasks with Remote Repositories

Annotation

Tags

Begin Version Control with Git

Create a Local Git Repository

Description Command
Initialize a New Git Repositorygit init
Clone an Existing Git Repositorygit clone [ URL ]

Track New Files

Description Command
Begin File Tracking by Namegit add [ file-name ]
Begin File Tracking by Typegit add [ *.filetype ]

Perform Initial Commit of Tracked Files

Description Command
Initial Commit of Tracked Files with Messagegit commit -m [ “Message Content” ]

Local Development with Git

State Reporting

Description Command
List Untracked Filesgit status
List New Tracked & Staged Filesgit status
List Modified Filesgit status
Indicate Working Branchgit status

View File Modifications

Description Command
Working Version vs. Staged Versiongit diff
Staged Version vs. Last Commit Versiongit diff --staged

File Edit Tasks

Description Command
Stage Modified, Tracked Files by Namegit add [ file-name ]
Stage Modified, Tracked Files by Typegit add [ *.filetype ]
Begin Tracking New File by Namegit add [ file-name ]
Begin Tracking New Files by Typegit add [ *.filetype ]
Reset Files to Last Commit, Preserve Tracked File Changesgit reset
Reset Files to Last Commit, Stage Tracked File Changesgit reset --soft
Reset Files to Last Commit, Discard Tracked File Changesgit reset --hard
Revert a File to the Last Commitgit checkout [ file-name ]
Stash Changes in Working Directory & Undo Unstaged Changesgit stash --keep-index
Restore Stashed Changes to Working Directorygit stash pop
Remove Tracked File from Index + Working Directorygit rm [ file-name ]
Remove Tracked File from Index, Leave in Working Directorygit rm --cached [ file-name ]

Commit Modified Version

Description Command
Commit Staged Changes with Messagegit commit -m [ “Message Content” ]
Commit All Tracked Files, Ignore Stage Statusgit commit -a -m [ “Message Content” ]

Branches and Merging

Description Command
Make New Branchgit branch [ name ]
Make New Branch, Checkout Branchgit checkout -b [ name ]
Checkout Branchgit checkout [ name ]
Merge Branchgit merge [ name ]
Merge State of Changesgit status
Abort Mergegit merge --abort
Delete Branchgit branch -d [ name ]

Commit Modification

Description Command
Change Last Commitgit commit --amend -m [ “Message” ]
Discard Last Commitgit reset HEAD~
Discard Last n Commitsgit reset HEAD~[ n ]
Revert Changes in Specific Commitgit revert [ SHA1 ]
Revert Changes n Commits Back from Tipgit revert HEAD~[ n ]

Viewing Commit History

Git Logs

Description Command
View Commit History, Current Branchgit log
View Commit History, Different Branchgit log [ branch ]
Single Line Logsgit log --oneline
List Changed Files in Loggit log --name-status
List Diff Stats in Loggit log --stat
View Commits that Changed String Occurrencesgit log -S [ string ]
View Commits that Changed Regex Match Occurrencesgit log -G [ regex ]
Log of All Actions Taken on Repository (Reflog)git log -g

Working with Remote Repositories

Tasks with Remote Repositories

Description Command
Clone a Remote Repositorygit clone [ URL ]
Pull Changes from Remote & Mergegit pull
Pull Changes from Remote & Rebasegit pull --rebase
Push Changes Up to Remotegit push
Add Branch to Remotegit push -u [ branch ]

Annotation

Tags

Description Command
Lightweight Tagsgit tag [ “Message” ]
Annotated Tagsgit tag -a [ “Version” ] -m [ “Message” ]