Helpful Git Commands

I assume pretty everyone is using git these days for source code control. Here are a list of pretty useful utilities that make git more pleasant to use.

Note: I didn’t create any of these. They’re mostly things I picked up from working at Twitter

Add the branch name to your terminal prompt

This simple set commands in your bash profile will automatically display your current branch name.

Git Aliases

It gets annoying after a while to have to type “git checkout” all the time. “git co” is easier.

Git Branch Name Autocomplete

This utility makes switching branches more pleasant. Simply type “git co xx” and hit tab to get a list of branch names that match “xx”.

Putting it all together in a .bash_profile…

# Git branch in prompt.
parse_git_branch() {
 git branch 2> /dev/null | sed -e ‘/^[^*]/d’ -e ‘s/* \(.*\)/ (\1)/’
}
export PS1=”\u@\h \W\[\033[32m\]\$(parse_git_branch)\[\033[00m\] $ “
# Add git auto completion to command line
if [ -f ~/.git-completion.bash ]; then
 . ~/.git-completion.bash
fi
Like what you read? Give Chad R a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.