Skip to main content

Magit: The Git Porcelain inside Emacs

·327 words·2 mins
[Your Name]
Author
[Your Name]
Capturing light with Sony A7R2, building workflows with NixOS & Emacs, exploring LLMs and Agents.
Table of Contents
Emacs Ecosystem - This article is part of a series.
Part 2: This Article

After using Magit, I never opened git log in a terminal again.

Magit is arguably the most powerful Git client in the Emacs ecosystem. It’s not just a wrapper around Git commands—it reimagines the entire Git workflow as an interactive interface.

Installation
#

(use-package magit
  :ensure t
  :bind ("C-x g" . magit-status))

Core Workflow
#

1. Check Repository Status
#

C-x g opens the magit-status buffer:

Head:     main Add series grouping
Merge:    origin/main Add series grouping

Untracked files (1)
  content/digital-life/magit-guide.md

Unstaged changes (2)
  modified   content/digital-life/emacs-config.md
  modified   content/digital-life/nixos-setup.md

Everything at a glance—ten times more readable than git status.

2. Committing Code
#

In the magit-status buffer:

KeyAction
sStage current file
uUnstage
c cWrite commit message (opens editor)
C-c C-cConfirm commit

3. History and Diff
#

KeyAction
l lView log
d dView diff
b bSwitch branch
P pPush to remote
F pPull from remote

4. Interactive Rebase
#

This is one of Magit’s killer features. r i enters interactive rebase mode, where you can:

  • Drag commits to reorder them
  • Mark commits as squash, fixup, or drop
  • Preview results in real time

No need to memorize git rebase -i syntax.

Advanced Tips
#

Blame Per Line
#

;; Blame current file
M-x magit-blame

Shows the last commit info for each line directly in the code margin.

Stage Partial Changes
#

Press TAB to expand a file in the diff region, then s to stage only the current hunk—no need for git add -p.

Quick Commit & Push
#

(defun my/magit-commit-and-push (message)
  (interactive "sCommit message: ")
  (magit-stage-modified)
  (magit-commit-create (list "-m" message))
  (magit-push-current-to-pushremote nil))

Comparison with Other Tools
#

ToolStartupUXEmacs Integration
Terminal GitFastPoorNone
LazygitFastGoodRequires switching windows
SourceTreeSlowMediocreNone
MagitMediumExcellentNative

For Emacs users, Magit’s integration is unbeatable—you’re already editing code, and one keystroke completes the entire Git workflow without context switching.


Next up: Org-mode Time Management in Practice

Emacs Ecosystem - This article is part of a series.
Part 2: This Article