Skip to content

Instantly share code, notes, and snippets.

@kezzico
Last active July 30, 2019 21:12
Show Gist options
  • Save kezzico/6fad2f09b8497c34db5ff9d733247606 to your computer and use it in GitHub Desktop.
Save kezzico/6fad2f09b8497c34db5ff9d733247606 to your computer and use it in GitHub Desktop.
Git cheat sheet

##GET LATEST

// Pull all branches. Sync local git with remote 'origin'

`git pull origin`

// Get latest from a single branch

`git fetch origin <branch>`

`git checkout <branch>`

##UNDO CHANGES

// Undo all local changes

`git reset --hard`


// Undo local changes made to a single file

`git checkout --theirs <file>`


// Undo all local changes, but save for later

`git stash`

// Bring back stashed changes

`git stash pop`

##SAVE CHANGE

// Save all staged changes locally

`git commit -m"I fixed it"`

// Stage a file for commit

`git add <file>`

// Unstage a file

`git reset HEAD <file>`

// Commit all stages/unstaged files

`git commit -a -m"all my local changes"`

##VIEW CHANGES

// See all changes made by a single commit

`git show <hash>`

// Compare local revision to previous commit/branch/tag

`git diff <hash>`

##BRANCHING

// Create a branch

`git branch <new-branch>`

// Switch to a branch/tag/single-commit

`git checkout <branch-name>`

// See all branches

`git branch -a`

##INFORMATION

// Web address of remote

`git remote -v`

// See local changes + current branch

`git status`

// See commit history for current branch

`git log`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment