Neogit and Diffview
Neogit is a full Git interface for Neovim modeled after Emacs Magit. Diffview provides a rich diff browser and merge conflict tool. Together, they form a complete Git client inside Neovim.
Core Idea
With Neogit, you can do status → stage → commit → push entirely inside Neovim using keyboard-driven workflows — without ever opening a terminal for git commands.
Installation
lua/plugins/git.lua (add to return table)
{
"NeogitOrg/neogit",
dependencies = {
"nvim-lua/plenary.nvim",
"sindrets/diffview.nvim", -- used by neogit for diffs
"nvim-telescope/telescope.nvim",
},
cmd = "Neogit",
keys = {
{ "<leader>gg", "<cmd>Neogit<cr>", desc = "Open Neogit" },
{ "<leader>gc", "<cmd>Neogit commit<cr>", desc = "Git commit" },
{ "<leader>gP", "<cmd>Neogit push<cr>", desc = "Git push" },
{ "<leader>gp", "<cmd>Neogit pull<cr>", desc = "Git pull" },
},
opts = {
kind = "split", -- open in split: "split" | "vsplit" | "floating" | "tab"
signs = {
hunk = { "", "" },
item = { ">", "v" },
section = { ">", "v" },
},
integrations = {
diffview = true,
telescope = true,
},
},
},
{
"sindrets/diffview.nvim",
cmd = { "DiffviewOpen", "DiffviewClose", "DiffviewToggleFiles", "DiffviewFocusFiles" },
keys = {
{ "<leader>gd", "<cmd>DiffviewOpen<cr>", desc = "Diff View: open" },
{ "<leader>gD", "<cmd>DiffviewClose<cr>", desc = "Diff View: close" },
{ "<leader>gh", "<cmd>DiffviewFileHistory %<cr>", desc = "File history" },
{ "<leader>gH", "<cmd>DiffviewFileHistory<cr>", desc = "Project history" },
},
opts = {},
},
Neogit Interface
Open with <leader>gg or :Neogit. The status window shows:
Head: main
Push: origin/main
Staged changes (1)
modified lua/config/options.lua
Unstaged changes (2)
modified lua/plugins/lsp.lua
deleted old-config.lua
Untracked files (1)
lua/plugins/new-plugin.lua
Inside Neogit Status
| Key | Action |
|---|---|
s | Stage item |
u | Unstage item |
S | Stage all |
U | Unstage all |
cc | Commit |
ca | Commit amend |
Pp | Push |
Ff | Pull (fast-forward) |
b | Branch popup |
r | Rebase popup |
<Enter> | Open/expand item |
= | Toggle inline diff |
q | Close |
? | Show all bindings |
Diffview
Open with <leader>gd or :DiffviewOpen.
Viewing Current Changes
:DiffviewOpen → diff of working tree vs HEAD
:DiffviewOpen HEAD~1 → diff vs parent commit
:DiffviewOpen origin/main → diff vs remote branch
:DiffviewOpen main..feature → compare two branches
File History
:DiffviewFileHistory % → history for current file
:DiffviewFileHistory → history for entire project
Navigate commits in the history panel with j/k, press Enter to see the diff.
Resolving Merge Conflicts with Diffview
:DiffviewOpen → shows conflicting files
In a conflict, Diffview opens a 3-way split:
| Ours (THEIRS) | Merged (conflict) | Theirs (OURS) |
| Key | Action |
|---|---|
[x / ]x | Previous/next conflict |
<leader>co | Choose ours |
<leader>ct | Choose theirs |
<leader>cb | Choose base |
<leader>ca | Choose all |
dx | Delete conflict region |
tip
After resolving, stage the file with s in Neogit status and commit.