GBrowse on main branch

The :GBrowse command from vim-fugitive is a great way to open a file or range in the configured upstream provider (e.g. GitHub). However, it’s usually a pain since it opens in the current branch, which is often not pushed.

Thankfully, there is a simple solution to this problem using the following command:

:GBrowse main:%

This will open the current file on the main branch instead of the current branch. You can also do this with a range.

:.,.+4GBrowse main:%