Emacs: git, magit-mode

By Xah Lee. Date: . Last updated: .

Magit tutorial for beginner.

All you need to know is Alt+x magit-status and 6 keys:

  1. Tab → toggle show diff.
  2. s → stage
  3. u → unstage
  4. c c → commit
  5. P → push
  6. F → pull
emacs magit status 2017 03 29
emacs magit-status. 2017-03-29

Following are details.

emacs magit-mode is the best interface to the git version control system.

I assume you have used the following git commands in terminal:

[see Git Basics]

Install Magit Mode

Install it thru MELPA. [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.

Alt+x magit-status to see the project's status.

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

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

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

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

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-commit-popup)


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


Press 【F】 to pull. (magit-pull-popup)


emacs magit-mode 2013-06-09
M-x magit-log

Alt+x 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 at the same dir magit-mode.el is at.

To view the doc:

  1. Alt+x describe-functionCtrl+h f】, then type magit-mode.
  2. Click on the file name to open the source code file, then Alt+x dired-jumpCtrl+x Ctrl+j】 to go into that dir. You'll see a file named magit.info
  3. Alt+x universal-argumentCtrl+u】, then Alt+x 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]

If you have a question, put $5 at patreon and message me.
Or Buy Xah Emacs Tutorial
Or buy a nice keyboard: Best Keyboards for Emacs


Emacs Lisp