sponsor Vim development Vim logo Vim Book Ad

Git Branch Info : A plugin for use on your status line to show info about Git branches

 script karma  Rating 6/10, Downloaded by 3314  Comments, bugs, improvements  Vim wiki

created by
Eustaquio Rangel de Oliveira Jr.
script type
This plugin show branches information on the status line.
To install, just put this file on ~/.vim/plugins and set your status line:

:set statusline=%{GitBranchInfoString}

Of course you can append this configuration to an existing one and make all
the customization you want on the status line, like:

:set statusline=%#ErrorMsg#%{GitBranchInfoString}%#StatusLine#

The command above will show the Git branches info on the same color as the
error messages. You can choose any color scheme you want to. Use

:help highlight-groups

to check for some other options.

There are some customization on the result string based on existing variables

let g:git_branch_status_head_current=1
This will show just the current head branch name

let g:git_branch_status_text="text"
This will show 'text' before the branches. If not set ' Git ' (with a trailing
left space) will be displayed.

let g:git_branch_status_nogit=""
The message when there is no Git repository on the current dir

let g:git_branch_status_around=""
Characters to put around the branch strings. Need to be a pair or characters,
the first will be on the beginning of the branch string and the last on the

let g:git_branch_status_ignore_remotes=1
Ignore the remote branches. If you don't want information about them, this can
make things works faster.

If you want to make your own customizations, you can use the GitBranchInfoTokens()
function. It returns an array with the current branch as the first element and
another array with the other branches as the second element, like:

:set statusline=%#ErrorMsg#%{GitBranchInfoTokens()[0]}%#StatusLine#


:set statusline=%#StatusLineNC#\ Git\ %#ErrorMsg#\ %{GitBranchInfoTokens()[0]}\ %#StatusLine#

will give you a nice custom formatted string.

This will show you the current branch only. No prefix text, no characters
around it. You can also make another functions to use the returned array.

Get the latest code on http://github.com/taq/vim-git-branch-info
install details
Download the zip file and unzip it on your .vim directory.

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
vim-git-branch-info.zip 0.1.5 2010-03-22 7.0 Eustaquio Rangel de Oliveira Jr. - Changed the buffer vars name with the prefix 'gbi' to try to make sure they will not clash with other vars on other scripts. At least now they are declarative to *this* script.
- Functions are now local to the script.
- Changed some functions scope
- Reorganizing functions and moved another one to the public scope.
- Implemented autogroup
vim-git-branch-info.zip 0.1.4 2009-10-13 7.0 Eustaquio Rangel de Oliveira Jr. Allow for branch names with slashs in them. Thanks to Thomas Adam.
vim-git-branch-info.zip 0.1.3 2009-06-01 7.0 Eustaquio Rangel de Oliveira Jr. Fixes bug that prevents git-buffer-info from finding the git-dir.
vim-git-branch-info.zip 0.1.2 2009-05-15 7.0 Eustaquio Rangel de Oliveira Jr. Seems that there were a little bug when loading the file from some other plugin
vim-git-branch-info.zip 0.1.1 2009-05-15 7.0 Eustaquio Rangel de Oliveira Jr. Changed the checking about the original branche while saving a file as a optional - and not default - option.
vim-git-branch-info.zip 0.1.0 2008-10-10 6.0 Eustaquio Rangel de Oliveira Jr. Fixed the .git relative path, thanks to rtwo for the patch.
vim-git-branch-info.zip 0.0.9 2008-07-13 7.0 Eustaquio Rangel de Oliveira Jr. There were a bug when rebasing. On this situation HEAD just have a hash and not the information about the branches the plugin looks for. Thanks for Joachim Bargsten for warning me about this.
I made a double check on the HEAD file. If there is not the information the script wants, a message about the condition is returned. If something also "explodes" there, there is a try/catch block.
If detect this rebase/merge/bisect situation, the file will be always saved without the branch verification.
vim-git-branch-info.zip 0.0.8 2008-06-26 7.0 Eustaquio Rangel de Oliveira Jr. Argh, another bug fixed. When trying to write to a file different from the current one, it was not saved. That happened because I was trying to save the file without it's name, presuming if we tell to save to another file with :w the name was correct.It was fixed using expand("<afile>"). Btw, there was another bug when trying to save to an existing file and need to use the bang (!) with write. It was fixed checking if a bang command was used and executing the bang version if needed.
vim-git-branch-info.zip 0.0.7 2008-06-19 7.0 Eustaquio Rangel de Oliveira Jr. Found a way of detecting if the file needs to be written. If it's a normal
buffer, it is written, if not, the GitBranchInfoWriteCheck() skip it.
Useful with other scripts that use temporary buffers like VCSCommand.
vim-git-branch-info.zip 0.0.6 2008-06-17 7.0 Eustaquio Rangel de Oliveira Jr. Extra check on permissions of the Git directory.
vim-git-branch-info.zip 0.0.5 2008-06-13 7.0 Eustaquio Rangel de Oliveira Jr. Removed remote branches on fetch menu, fetch just the remote repository
vim-git-branch-info.zip 0.0.4 2008-06-11 7.0 Eustaquio Rangel de Oliveira Jr. Some label changes and the fetch remote branches feature.
Added some variables to store the current buffer Git dir and the branch where the buffer was loaded.
Added autocmd's to fill the variables above.
Added an alert when the branch where the file is being saved is different from where it was loaded.
If the current buffer is not on the local dir, make a CD to the buffer dir when need to make a checkout or a fetch.
Changed to ask if we want to save a file loaded from one branch into another branch.
vim-git-branch-info.zip 0.0.3 2008-06-06 7.0 Eustaquio Rangel de Oliveira Jr. Added a menu system with some features for branch changing.
vim-git-branch-info.zip 0.0.2 2008-06-05 7.0 Eustaquio Rangel de Oliveira Jr. - Changed version number.
- The previous version performance SUCKED a lot. I removed the system()
call to Vim internal file functions and seems that now things are really faster.
  - Removed the g:git_branch_status_all option and changed to g:git_branch_status_head_current, who just shows the current head branch. This can make things faster because if does not seeks for the other branches and  just show the current branch with GitBranchInfoString.
- Added the feature to find the remote branches (which we're not using right now but I have some plans) and the option g:git_branch_status_ignore_remotes to avoid this feature if you don't need it.
- Fixed some errors on the statusline samples using GitBranchInfoTokens.
- Created the variable to handle the remote list on GitBranchInfoString.
- Changed the way GitBranchInfoString returns the info string, based on the configuration chosen.
- GitBranchInfoTokens() was fully rewritten because of the previous poor performance.
vim-git-branch-info.zip 0.0.1 2008-06-05 7.0 Eustaquio Rangel de Oliveira Jr. Initial upload
ip used for rating:

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.