Skip to content

Instantly share code, notes, and snippets.

@jaredkc
Last active September 25, 2017 17:03
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jaredkc/5732205 to your computer and use it in GitHub Desktop.
Save jaredkc/5732205 to your computer and use it in GitHub Desktop.
GIT Cheat Sheet

Git Cheat Sheet

Branches

Delete remote branch: git push origin :<branchName>

Add a remote branch: git remote add <remoteName> <gitAddress>

Remove local branches that are no longer on origin: git fetch --prune

Add remote to existing local rep, and track master: git remote add --track master origin git@github.com:abc/123.git

Remotes

Showing remotes: git remote -v

Set remote repo: git remote set-url origin git@github.com:account/whatever.git

Revert and Undo

Undo previous commit: git revert HEAD^

Modify previous commit message: git commit --amend

Reset to the most recent commit git reset --hard

Stash

Temporarily stash changes: git stash

Restore changes from stash: git stash pop

Delete changes in stash: git stash drop

Status

Show status with list modified/new/etc files: git status -s

Submodules

Add a new submodule: git submodule add git@mygithost:repo path/to/dir

Update all the submodules (externals): git submodule update --init --recursive

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