Skip to content

Instantly share code, notes, and snippets.

@brigand
Created October 6, 2014 02:50
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save brigand/56009f059360cb455de0 to your computer and use it in GitHub Desktop.
Save brigand/56009f059360cb455de0 to your computer and use it in GitHub Desktop.
My Git Aliases

I use git a lot for work and other projects, so I invested the time in creating some high quality aliases that really work for me. These just go in your bash profile (~/.bash_profile or ~/.bashrc or ~/.profile depending on your OS).

I see a lot of people go overboard with aliases, and then end up not using them. They're meant to cover 95% of the commands I use, not 100%.

alias gcam='git commit -am'
alias gs='git status'
alias gplr='git pull --rebase'
alias gpsh='git push'
alias gpo='git push -u origin `git symbolic-ref --short HEAD`'
alias glg='git log'

Basics

So let's say I made some changes, and no one else is working on this repo.

$ gs
$ gcam "changed some stuff"
$ gpsh

Done. Written out that would look like this:

git status
git commit -am "changed some stuff"
git push

That's a lot more typing, and I do this many times per day.

Pull

When working with other people, you need to pull in their changes. I pretty much always forget to add --rebase when pulling, which is the main reason I created the gpr macro.

gs
gcam "made some changes"
grp
gpsh

gpo and glg

These are questionable, because I only sometimes use them. They're the last 3% to get up to 95%. gpom is for when you create a new repo/branch, and you need to tell it where to track to (for some reason git is difficult about this...).

git log is just generally useful, and I check it fairly frequently, though I prefer github's ui most of the time.

Extra fun!

I found this online somewhere, and modified it a bit.

function git_branch_name () {
  __CURRENT_GIT_BRANCH=$(git symbolic-ref HEAD --short 2>/dev/null )
  if [ -n "$__CURRENT_GIT_BRANCH" ]; then
    __CURRENT_GIT_BRANCH=" ${__CURRENT_GIT_BRANCH}"
  fi
  echo -n "$__CURRENT_GIT_BRANCH"
}

PROMPT_COMMAND='PS1="\W$(git_branch_name) \$ "'

It looks really really crazy, but it basically makes my terminal prompt show "{DIR} {BRANCH} $" instead of the useless information about the computer I'm on... I know which computer I'm on...

When not in a git repo, it just shows the directory name. It's nice to be able to not type anything and see where I am.


Hope there's something you can use here to improve your workflow!

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