back to TILs

GBrowse to another branch with Fugitive.vim

Last week, I watched a coworker bring up a file on a different branch using fugitive.vim’s :GBrowse and I was floored: almost daily I find myself using it to open the URL to a file to share (or a few lines).

However, much of the time I’m working on a different branch than the one I want to share, and navigating to the same file on a different branch in the GitHub UI takes too many steps. First, you realize you’re on the wrong branch, then you change branches, then you have to navigate back to the file again.

I had always been vaguely aware of :h fugitive-object, but had never put them to use.

The object you’re looking for is <branch>:%, meaning: bring up this file (%) on branch <branch>.

For example:

:GBrowse main:%

And of course, this just works with all of the :GBrowse variants.