Skip to content

Instantly share code, notes, and snippets.

@pfrazee
Last active November 2, 2016 19:07
Show Gist options
  • Select an option

  • Save pfrazee/3ccbf79caa2cfee958470298cc342da0 to your computer and use it in GitHub Desktop.

Select an option

Save pfrazee/3ccbf79caa2cfee958470298cc342da0 to your computer and use it in GitHub Desktop.
Some git tips

Two quick tips that I use all the time.

Tip 1: Shortcuts.

Put this file in your home directory somewhere (eg ~/.git-shortcuts):

alias s='git status'
alias co='git checkout'
alias c='git commit -m'
alias b='git branch'
alias push='git push'
alias pull='git pull'
alias d='git diff'
alias dc='git diff --cached'
alias a='git add'

Then add this line to ~/.bash_profile:

. ~/.git-shortcuts

This makes working with git repos SUPER easy:

co my-branch # checkout a branch
pull # pull latest
s # check status
d # see unstage diffs
a * # add everything
dc # see the staged diffs
c "my commit" # commit with the given message
push # push to remote

Tip 2: add -p

If you want to review the changes you're staging, or you want to only pick out a few changes, add the -p parameter:

git add -p *
a -p # with my shortcuts

There will be instructions along the bottom of the CLI. The commands I use are y for yes, n for no, s for split the chunk, and ctrl+c for cancel.

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