Referencing the git tracking branch

by jenny on 15 May 2012 - 05:32pm in

Why something similar to this isn’t a built-in git command is beyond me. Here’s a handy alias to add to your .gitconfig. It simply prints the currently tracked branch to the screen. Invoke via git tracking.

        ; Print the tracked branch
        tracking = "!head=$(git symbolic-ref HEAD) && head=${head#refs/heads/} && tracking=$(git config branch.$head.merge) && tracking=$(git config branch.$head.remote)${tracking#refs/heads} && tracking=${tracking#./} && echo $tracking"

With that in place, we open up a world of possibilities.

        ; Log (since) tracking: log commits not yet in tracked branch
        lt = !git log $(git tracking)..

        ; Log check tracking: log commits on tracked branch not yet in current branch
        lct = !git remote update && git log ..$(git tracking)

        ; Interactively rebase commits since the tracked branch
        ri = !git rebase -i $(git tracking)

Do let me know if you’ve found a better way of doing this.