After using Magit, I never opened
git login 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.mdEverything at a glance—ten times more readable than git status.
2. Committing Code#
In the magit-status buffer:
| Key | Action |
|---|---|
s | Stage current file |
u | Unstage |
c c | Write commit message (opens editor) |
C-c C-c | Confirm commit |
3. History and Diff#
| Key | Action |
|---|---|
l l | View log |
d d | View diff |
b b | Switch branch |
P p | Push to remote |
F p | Pull 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-blameShows 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#
| Tool | Startup | UX | Emacs Integration |
|---|---|---|---|
| Terminal Git | Fast | Poor | None |
| Lazygit | Fast | Good | Requires switching windows |
| SourceTree | Slow | Mediocre | None |
| Magit | Medium | Excellent | Native |
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