Neogit
An interactive and powerful Git interface for Neovim, inspired by Magit
Install / Use
/learn @NeogitOrg/NeogitREADME
<div align="center">
<div>
<div><img src="https://github.com/NeogitOrg/neogit/assets/7228095/7684545f-47b5-40e2-aedd-ccf56e0553f4" width="400px"/></div>
<div><h1>Neogit</h1></div>
</div>
<table>
<tr>
<td>
<strong>A git interface for <a href="https://neovim.io">Neovim</a>, inspired by <a href="https://magit.vc">Magit</a>.</strong>
</td>
</tr>
</table>
<a href="https://dotfyle.com/plugins/NeogitOrg/neogit">
<img src="https://dotfyle.com/plugins/NeogitOrg/neogit/shield?style=for-the-badge" />
</a>
Installation
Here's an example spec for Lazy, but you're free to use whichever plugin manager suits you.
{
"NeogitOrg/neogit",
lazy = true,
dependencies = {
"nvim-lua/plenary.nvim", -- required
-- Only one of these is needed.
"sindrets/diffview.nvim", -- optional
"esmuellert/codediff.nvim", -- optional
-- For a custom log pager
"m00qek/baleia.nvim", -- optional
-- Only one of these is needed.
"nvim-telescope/telescope.nvim", -- optional
"ibhagwan/fzf-lua", -- optional
"nvim-mini/mini.pick", -- optional
"folke/snacks.nvim", -- optional
},
cmd = "Neogit",
keys = {
{ "<leader>gg", "<cmd>Neogit<cr>", desc = "Show Neogit UI" }
}
}
Usage
You can either open Neogit by using the Neogit command:
:Neogit " Open the status buffer in a new tab
:Neogit cwd=<cwd> " Use a different repository path
:Neogit cwd=%:p:h " Uses the repository of the current file
:Neogit kind=<kind> " Open specified popup directly
:Neogit commit " Open commit popup
" Map it to a key
nnoremap <leader>gg <cmd>Neogit<cr>
-- Or via lua api
vim.keymap.set("n", "<leader>gg", "<cmd>Neogit<cr>", { desc = "Open Neogit UI" })
Or using the lua api:
local neogit = require('neogit')
-- open using defaults
neogit.open()
-- open a specific popup
neogit.open({ "commit" })
-- open as a split
neogit.open({ kind = "split" })
-- open with different project
neogit.open({ cwd = "~" })
-- You can map this to a key
vim.keymap.set("n", "<leader>gg", neogit.open, { desc = "Open Neogit UI" })
-- Wrap in a function to pass additional arguments
vim.keymap.set(
"n",
"<leader>gg",
function() neogit.open({ kind = "split" }) end,
{ desc = "Open Neogit UI" }
)
The kind option can be one of the following values:
tab(default)replacesplitsplit_abovesplit_above_allsplit_belowsplit_below_allvsplitfloatingauto(vsplitif window would have 80 cols, otherwisesplit)
Configuration
You can configure neogit by running the require('neogit').setup {} function, passing a table as the argument.
local neogit = require("neogit")
neogit.setup {
-- Use Treesitter to apply syntax highlighting to diff hunks
treesitter_diff_highlight = true,
-- Apply word-diff highlights to diff hunks
word_diff_highlight = true,
-- Hides the hints at the top of the status buffer
disable_hint = false,
-- Disables changing the buffer highlights based on where the cursor is.
disable_context_highlighting = false,
-- Disables signs for sections/items/hunks
disable_signs = false,
-- Path to git executable. Defaults to "git". Can be used to specify a custom git binary or wrapper script.
git_executable = "git",
-- Offer to force push when branches diverge
prompt_force_push = true,
-- Request confirmation when amending already published commits
prompt_amend_commit = true,
-- Changes what mode the Commit Editor starts in. `true` will leave nvim in normal mode, `false` will change nvim to
-- insert mode, and `"auto"` will change nvim to insert mode IF the commit message is empty, otherwise leaving it in
-- normal mode.
disable_insert_on_commit = "auto",
-- When enabled, will watch the `.git/` directory for changes and refresh the status buffer in response to filesystem
-- events.
filewatcher = {
interval = 1000,
enabled = true,
},
-- "ascii" is the graph the git CLI generates
-- "unicode" is the graph like https://github.com/rbong/vim-flog
-- "kitty" is the graph like https://github.com/isakbm/gitgraph.nvim - use https://github.com/rbong/flog-symbols if you don't use Kitty
graph_style = "ascii",
-- Show relative date by default. When set, use `strftime` to display dates
commit_date_format = nil,
log_date_format = nil,
-- When set, used to format the diff. Requires *baleia* to colorize text with ANSI escape sequences. An example for `Delta` is `{ 'delta', '--width', '117' }`. For `Delta`, hyperlinks must be disabled when called by `neogit`, for text to be colorized properly.
log_pager = nil,
-- Show message with spinning animation when a git command is running.
process_spinner = false,
-- Used to generate URL's for branch popup action "pull request", "open commit" and "open tree"
git_services = {
["github.com"] = {
pull_request = "https://github.com/${owner}/${repository}/compare/${branch_name}?expand=1",
commit = "https://github.com/${owner}/${repository}/commit/${oid}",
tree = "https://${host}/${owner}/${repository}/tree/${branch_name}",
},
["bitbucket.org"] = {
pull_request = "https://bitbucket.org/${owner}/${repository}/pull-requests/new?source=${branch_name}&t=1",
commit = "https://bitbucket.org/${owner}/${repository}/commits/${oid}",
tree = "https://bitbucket.org/${owner}/${repository}/branch/${branch_name}",
},
["gitlab.com"] = {
pull_request = "https://gitlab.com/${owner}/${repository}/merge_requests/new?merge_request[source_branch]=${branch_name}",
commit = "https://gitlab.com/${owner}/${repository}/-/commit/${oid}",
tree = "https://gitlab.com/${owner}/${repository}/-/tree/${branch_name}?ref_type=heads",
},
["azure.com"] = {
pull_request = "https://dev.azure.com/${owner}/_git/${repository}/pullrequestcreate?sourceRef=${branch_name}&targetRef=${target}",
commit = "",
tree = "",
},
["codeberg.org"] = {
pull_request = "https://${host}/${owner}/${repository}/compare/${branch_name}",
commit = "https://${host}/${owner}/${repository}/commit/${oid}",
tree = "https://${host}/${owner}/${repository}/src/branch/${branch_name}",
},
},
-- Allows a different telescope sorter. Defaults to 'fuzzy_with_index_bias'. The example below will use the native fzf
-- sorter instead. By default, this function returns `nil`.
telescope_sorter = function()
return require("telescope").extensions.fzf.native_fzf_sorter()
end,
-- Persist the values of switches/options within and across sessions
remember_settings = true,
-- Scope persisted settings on a per-project basis
use_per_project_settings = true,
-- Table of settings to never persist. Uses format "Filetype--cli-value"
ignored_settings = {},
-- Configure highlight group features
highlight = {
italic = true,
bold = true,
underline = true
},
-- Set to false if you want to be responsible for creating _ALL_ keymappings
use_default_keymaps = true,
-- Neogit refreshes its internal state after specific events, which can be expensive depending on the repository size.
-- Disabling `auto_refresh` will make it so you have to manually refresh the status after you open it.
auto_refresh = true,
-- Value used for `--sort` option for `git branch` command
-- By default, branches will be sorted by commit date descending
-- Flag description: https://git-scm.com/docs/git-branch#Documentation/git-branch.txt---sortltkeygt
-- Sorting keys: https://git-scm.com/docs/git-for-each-ref#_options
sort_branches = "-committerdate",
-- Value passed to the `--<commit_order>-order` flag of the `git log` command
-- Determines how commits are traversed and displayed in the log / graph:
-- "topo" topological order (parents always before children, good for graphs, slower on large repos)
-- "date" chronological order by commit date
-- "author-date" chronological order by author date
-- "" disable explicit ordering (fastest, recommended for very large repos)
commit_order = "topo",
-- Default for new branch name prompts
initial_branch_name = "",
-- Default for rename branch prompt. If not set, the current branch name is used
initial_branch_rename = nil,
-- Change the default way of opening neogit
kind = "tab",
-- Floating window style
floating = {
relative = "editor",
width = 0.8,
height = 0.7,
style = "minimal",
border = "rounded",
},
-- Disable line numbers
disable_line_numbers = true,
-- Disable relative line numbers
disable_relative_line_numbers = true,
-- The time after which an output console is shown for slow running commands
console_timeout = 2000,
-- Automatically show console if a command takes more than console_timeout milliseconds
auto_show_console = true,
-- Automatically close the console if the process exits with a 0 (success) status
auto_close_console = true,
notification_icon = "",
status = {
show_head_commit_hash = true,
recent_commit_count = 10,
HEAD_padding = 10,
HEAD_folded = false,
mode_padding = 3,
mode_text = {
M = "modified",
N = "new file",
A = "added",
D = "deleted",
