git guess-upstream


– tags: git

A small script you can use to quickly make your branch track the upstream branch with the same name.

Names don’t mean anything for git, but they do for me and my collegues. Very often, if not always, the branch names on a remote correspond to the local branch that you want to work on. So that’s what this script is for. Life is too short to type git branch --set-upstream-to origin/something.

$ cat ~/bin/git-guess-upstream

#!/usr/bin/env ruby

current_branch = `git rev-parse --abbrev-ref HEAD`.strip
STDERR.puts "    git branch --set-upstream-to \"origin/#{current_branch}\""
`git branch --set-upstream-to "origin/#{current_branch}"`

Maybe I should rewrite it in Bash or so.

Installing

Copy the script to a file, make it executable and put it in a directory in your path. I recommend you use ~/bin or /usr/local/bin.