🤖🚫 AI-free content. This post is 100% written by a human, as is everything on my blog. Enjoy!

Some custom git commands that I use

July 30, 2015, revised December 4, 2015 in Software

Git has two internal layers of commands - the so-called “plumbing” and “porcelain” commands. The former are low-level structural management commands which we don’t typically use, and the latter form the core of the user interface, such as “push”, “pull”, and so forth.

It only makes sense to develop a third, personal, layer of git commands to help in your daily routine - call them “towel” or “toothbrush” commands, if you like.

You can configure custom git commands through git aliases, but I find it more convenient to set them up as shell scripts: to create git customcommand, put a git-customcommand shell script somewhere on your $PATH and make it executable. For example, I put such scripts into ~/bin.

git workon

When you are going to work on a branch that already exists on the upstream, save yourself some typing by setting the upstream.


git workon feature/feature-branch

Source code:

git fetch origin $1:$1
git checkout $1
git auto-upstream

git pr

Open a Github compare view between the current branch and the main branch (dev, if it exists, otherwise master). From there you can create a pull request or open the currently open pull request.


git pr

Source code (fixed 2015-12-04):

# Call with `git pr` to open a compare view for the current branch and a pull request from that
# Depends on https://hub.github.com/

git rev-parse --verify dev >/dev/null 2>/dev/null

if [ $? -eq 0 ]

hub compare $BASE_BRANCH...`git rev-parse --abbrev-ref HEAD | sed 's/\//%2F/g'`

Depends on hub - a suite of Github-related git commands, which I highly recommend.

git cleanup

Delete all branches that are already merged into the current one. I run it from time to time on the master branch for housekeeping.


git cleanup

Source code:

git branch --merged | grep -v \* | grep -v master | xargs git branch -D

git timesheet

Produce a timestamped list of your commits for accounting purposes.


git timesheet --since 2015-07-01

Source code: git-timesheet on Github

Buy me a coffee Liked the post? Treat me to a coffee