Skip to content

Instantly share code, notes, and snippets.

@maxcampolo
Last active August 11, 2016 13:43
Show Gist options
  • Save maxcampolo/02b39dfd28781d509b7b435608701ada to your computer and use it in GitHub Desktop.
Save maxcampolo/02b39dfd28781d509b7b435608701ada to your computer and use it in GitHub Desktop.
Handy Git cheat sheet.
// Remove or add a file
git rm path/to/file
git add path/to/file
// Resetting state
// Revert working copy
git checkout .
// Revert unpushed commits
git reset
// Revert one commit
git revert ...
// Remove untracked files (new files)
git clean -f
// Remove untracked files & directories
git clean -fd
// Revert all changes and be up to date with remote master
git reset --hard
// Stashing
// Stash changes
git stash
// Apply stashed changes
git stash apply
// Remove top stashed change
git stash pop
// Remove stash
git stash drop
// Tagging
// Anotated tag
git tag -a 1.0 -m 'the initial release'
// Lightweight tag
git tag 'tempTag'
// Push tags to remote
git push origin --tags
// View tags
git tag
// Delete remote tag
git tag -d 12345
git push origin :refs/tags/12345
// Branches
// Create branch
git checkout -b branchName
// Create branch and track remote
git checkout -b branchName remote/remoteBranchName
// View branches
git branch
// Delete branch
git branch -D branchName
// Delete remote branch
git push origin --delete <branchName>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment