Fugitive is the premier Vim plugin for Git. Or maybe it's the premier Git plugin for Vim? Either way, it's "so awesome, it should be illegal". That's why it's called Fugitive.
The crown jewel of Fugitive is
:Git (or just
:G), which calls any
arbitrary Git command. If you know how to use Git at the command line, you
know how to use
:Git. It's vaguely akin to
:!git but with numerous
- The default behavior is to directly echo the command's output. Quiet
:Git addavoid the dreaded "Press ENTER or type command to continue" prompt.
:Git rebase -i, and other commands that invoke an editor do their editing in the current Vim instance.
:Git log, and other verbose, paginated commands have their output loaded into a temporary buffer. Force this behavior for any command with
:Git blameuses a temporary buffer with maps for additional triage. Press enter on a line to view the commit where the line changed, or
g?to see other available maps. Omit the filename argument and the currently edited file will be blamed in a vertical, scroll-bound split.
:Git difftoolload their changesets into the quickfix list.
- Called with no arguments,
:Gitopens a summary window with dirty files and unpushed and unpulled commits. Press
g?to bring up a list of maps for numerous operations including diffing, staging, committing, rebasing, and stashing. (This is the successor to the old
- This command (along with all other commands) always uses the current buffer's repository, so you don't need to worry about the current working directory.
Additional commands are provided for higher level operations:
- View any blob, tree, commit, or tag in the repository with
:Gsplit, etc.). For example,
:Gedit HEAD~3:%loads the current file as it existed 3 commits ago.
:Gvdiffsplit) brings up the staged version of the file side by side with the working tree version. Use Vim's diff handling capabilities to apply changes to the staged version, and write that buffer to stage the changes. You can also give an arbitrary
:Geditargument to diff against older versions of the file.
:Greadis a variant of
git checkout -- filenamethat operates on the buffer rather than the file itself. This means you can use
uto undo it and you never get any warnings about the file changing outside Vim.
:Gwritewrites to both the work tree and index versions of a file, making it like
git addwhen called from a work tree file and like
git checkoutwhen called from the index or a blob in history.
:lgrepfor the same.
git mvon the current file and changes the buffer name to match.
:GRenamedoes the same with a destination filename relative to the current file's directory.
git rmon the current file and simultaneously deletes the buffer.
:GRemovedoes the same but leaves the (now empty) buffer open.
:GBrowseto open the current file on the web front-end of your favorite hosting provider, with optional line range (try it in visual mode). Plugins are available for popular providers such as GitHub, GitLab, Bitbucket, Gitee, Pagure, Phabricator, Azure DevOps, and sourcehut.
'statusline' to get an indicator
with the current branch in your statusline.
For more information, see
- A complement to command line git
- Working with the git index
- Resolving merge conflicts with vimdiff
- Browsing the git object database
- Exploring the history of a git repository
Install using your favorite package manager, or use Vim's built-in package support:
mkdir -p ~/.vim/pack/tpope/start cd ~/.vim/pack/tpope/start git clone https://tpope.io/vim/fugitive.git vim -u NONE -c "helptags fugitive/doc" -c q
What happened to the dispatch.vim backed asynchronous
This behavior was divisive, confusing, and complicated inputting passwords, so
it was removed. Use
:Dispatch git push for effectively the same behavior,
or provide your own asynchronous
:Gfetch by adding the
following to your vimrc:
command! -bang -bar -nargs=* Gpush execute 'Dispatch<bang> -dir=' . \ fnameescape(FugitiveGitDir()) 'git push' <q-args> command! -bang -bar -nargs=* Gfetch execute 'Dispatch<bang> -dir=' . \ fnameescape(FugitiveGitDir()) 'git fetch' <q-args>
So I have a symlink and...
Stop. Just stop. If Git won't deal with your symlink, then Fugitive won't either. Consider using a plugin that resolves symlinks, or even better, using fewer symlinks.
Copyright (c) Tim Pope. Distributed under the same terms as Vim itself.