Emacs: magit-mode Tutorial

By Xah Lee. Date: . Last updated: .

This page is a tutorial of emacs magit-mode. Magit mode is a excellent interface to the git version control system.

I assume you have used the following git commands in terminal: {git status, git add, git commit, git push, git pull}. If not, see Git Basics.

emacs magit-mode status diff screenshot 2015-08-10
emacs magit-mode at work.

Install Magit Mode

Install it thru MELPA. Just add MELPA and call list-packages. 〔➤see Emacs: How to Install Packages Using ELPA, MELPA

Using Magit to add, commit, push

First, open a git controlled file, or open its directory in dired.

Call magit-status to see the project's status.

emacs magit-mode status screenshot 2015-08-05
emacs magit-mode status screenshot.

WARNING: magit around changed its keybinding again. The following is good for magit version in most of . To find out the commands/keys in your magit version, in magit mode, press 【Ctrl+h m】 to see the keybinding.

Move cursor to a line, press Tab ↹ to toggle “diff”. (magit-section-toggle (was “magit-toggle-section”))

Press 【s】 to add the file under cursor to stage. (magit-stage (was “magit-stage-item”))

Press 【S】 to add all tracked files to stage. ( magit-stage-modified (was “magit-stage-all”))

Press 【u】 to unstage the file under cursor. (magit-unstage (was “magit-unstage-item”))

Press 【U】 to unstage all staged files. (magit-reset-index (was “magit-unstage-all”))

Press 【c c】 to write a commit message, then 【Ctrl+c Ctrl+c】 to commit. (magit-commit-popup (was “magit-key-mode-popup-committing”))

Note: in magit version dated or later, some command names have changed. So the above may not be exactly what you have.


Press 【P P】 to push. (magit-push-popup (was “magit-key-mode-popup-pushing”))


Press 【F F】 to pull. (magit-pull-popup (was “magit-key-mode-popup-pulling”))


emacs magit-mode 2013-06-09
Emacs magit-log screen.

Call magit-log to see your commit log. Press Enter ↵ on a line to see its diff.

View Magit Documentation

Magit comes with complete documentation. It's located at the same dir magit-mode.el is at.

To view the doc:

  1. Call describe-functionCtrl+h f】, then type magit-mode.
  2. Click on the file name to open the source code file, then call dired-jumpCtrl+x Ctrl+j】 to go into that dir. You'll see a file named magit.info
  3. Call universal-argumentCtrl+u】, then call infoCtrl+h i】, then type the file name.

Once you've done this, the Magit doc is added to the info index. So, you can just call infoCtrl+h i】 to view it next time. 〔➤see Emacs: View Info Page

Like it? Buy Xah Emacs Tutorial. Thanks.