Skip to content

Instantly share code, notes, and snippets.

@adcreare
Last active March 5, 2018 21:18
Show Gist options
  • Save adcreare/23b3204a5bb1654dd9877643e5873946 to your computer and use it in GitHub Desktop.
Save adcreare/23b3204a5bb1654dd9877643e5873946 to your computer and use it in GitHub Desktop.
Handy Git commands

The git commands I always forget!

Branches

  • List all local branches: git branch -a
  • Remove local branch: git branch -d $branchname
  • Cleanup branches that are on your local as remote but aren't remote anymore: git remote prune origin --dry-run (remove --dry-run to do it for real)

Commits

  • add specific lines of a file: git add -i $FILENAME
  • remove last commit (before push): git reset --hard HEAD^
Amending previous commit
  • amend previous commit and add file: git commit --amend src/file.ts
  • amend previous commit message: git commit --amend

Diffs

show file names only: git diff --stat show difference between current and previous head commits git diff HEAD^ HEAD

Merging

on conflict keep mine: git checkout --ours filename.ex

Listing

show last 10 - leave them in cli histroy git log --pretty=oneline |head -n 10

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