Skip to content
Jonas Bernoulli edited this page Mar 25, 2022 · 10 revisions

You might also be interested in the Magit Reference Card (pdf).

Section commands

These commands are for navigation and to change the visibility of sections.

Key Description
TAB toggle body of current section
C-<tab> cycle visibility of current section and its children
M-<tab> cycle visibility of all diff sections
s-<tab> cycle visibility of all sections
1, 2, 3, 4 show surrounding sections up to level N, hide deeper levels
M-1, M-2, M-3, M-4 globally show sections up to level N, hide deeper levels
^ goto parent section
p goto beginning of section, from there to previous section
n goto next section
M-p goto beginning of section, from there to previous sibling section
M-n goto next sibling section

Buffer commands

Key Description
g refresh current buffer and status buffer, possibly revert file-visiting buffers
G refresh all Magit buffers and revert all file-visiting buffers in repository
q bury the current Magit buffer, restoring previous window configuration
C-u q kill the current Magit buffer, restoring previous window configuration

Various common commands

Key Description
SPC scroll up (1)
DEL scroll down (1)
RET show the thing at point in another buffer (2)
j jump somewhere (3)
$ show output of recent calls to git
  • (1) In most Magit buffers this scrolls the current buffer. In log buffers this instead scrolls the diff buffer shown in another window.
  • (2) What is being shown depends on the context.
  • (3) Where this jumps to depends on the context.

Various assorted commands

Key Description
i add a gitignore rule globally
I add a gitignore rule locally
x reset using --mixed
C-u x reset using --hard

Prefix commands

These popup/prefix commands are available in all Magit buffers using these key bindings. They are also available indirectly from the “dispatch prefix” (aka the “the popup of popups”), which itself is available in Magit buffers on h. In non-Magit buffers that dispatcher is available on C-x M-g.

Therefore you don’t have to memorize all these bindings, just h and maybe C-x M-g.

Key Description
A cherry-pick
b branch
B bisect
c commit
d diff
E ediff
f fetch
F pull
h, ? show popup of popups
l log
m merge
M remote
o submodule
P push
r rebase
t tag
T note
V revert
w apply patches
C-u y list refs (1)
z stash
! run git or gui tool
  • (1) Actually y is bound to a popup/prefix command, but it is one of the few popups which default to a suffix command and therefore has to be called with a prefix argument to actually show the popup buffer.

Applying changes

Key Description
a apply the change at point
k discard the change at point
s stage the change at point
S stage all unstaged changes
u unstage the change at point
U unstage all staged changes (1)
v reverse the change at point
  • (1) Actually this asks for a commit to reset the index too. If you just press RET, then what this equivalent to unstaging everything. If that is too confusing then just bind this key to magit-unstage-all.

Diffing

These commands show diffs or manipulate the diff arguments used to generate the diffs in the current buffer.

Key Description
RET (on commit) show commit
RET (on stash) show stash
d show diffing popup
D show popup for changing diff arguments
e use ediff to stage, compare, or stage (dwim)
E show ediffing popup (for when dwimming fails)
+ show more context lines
- show less context lines
0 show default amount of context lines (three)

Rebasing

The following commands can be used from the magit-rebase-popup which is activated using r

Key Description
i Start an interactive rebase sequence.
f Combine squash and fixup commits with their intended targets.
m Edit a single older commit using rebase.
w Reword a single older commit using rebase.
k Remove a single older commit using rebase.

Whilst performing a rebase the following editing sequences are available.

Key Description
C-c C-c Finish the current editing session by returning with exit code 0. Git then uses the rebase instructions it finds in the file.
C-c C-k Cancel the current editing session by returning with exit code 1. Git then forgoes starting the rebase sequence.
RET Show the commit on the current line in another buffer and select that buffer.
SPC Show the commit on the current line in another buffer without selecting that buffer. If the revision buffer is already visible in another window of the current frame, then instead scroll that window up.
DEL Show the commit on the current line in another buffer without selecting that buffer. If the revision buffer is already visible in another window of the current frame, then instead scroll that window down.
p Move to previous line.
n Move to next line.
M-p Move the current commit (or command) up.
M-n Move the current commit (or command) down.
r Edit message of commit on current line.
e Stop at the commit on the current line.
s Meld commit on current line into previous commit, and edit message.
f Meld commit on current line into previous commit, discarding the current commit’s message.
k Kill the current action line.
c Use commit on current line.
x Insert a shell command to be run after the proceeding commit.
y Read an arbitrary commit and insert it below current line.
C-x u Undo some previous changes. Like undo but works in read-only buffers.

If a rebase is already in progress then magit-rebase-popup offers the following commands.

Key Description
r Restart the current rebasing operation.
s Skip the current commit and restart the current rebase operation.
e Edit the todo list of the current rebase operation.
a Abort the current rebase operation, restoring the original branch.