Emacs: magit-mode Tutorial

Buy Xah Emacs Tutorial. Master emacs benefits for life.
, , …,

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

I assume you know how to use basic git command such as {git status, git add, git commit, git push, git pull} in terminal. If not, see git real basics.

Install Magit Mode

Install it thru MELPA. Just add MELPA and call list-packages. 〔➤ Emacs 24 Packages (ELPA) Tutorial

Using Magit to add, commit, push

Call dired and go into a dir of your git repository, or open one of your git controlled file.

Call magit-status to see your status.

emacs magit-mode status screenshot 2013-06-08
emacs magit-mode status screenshot

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

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

Press 【S】 to add all tracked files to stage. (magit-stage-all)

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

Press 【U】 to unstage all staged files. (magit-unstage-all)

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


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


Press 【F F】 to pull. (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 also: Emacs: Info-mode Keys.

Like it? Buy Xah Emacs Tutorial.
blog comments powered by Disqus