7.2 KiB
7.2 KiB
Doom Emacs Magit Cheatsheet
🚀 What is Magit?
Magit is an extremely powerful tool for managing your Git project
- Visual, interactive Git workflows
- Stage hunks, lines, or entire files with ease
- Commit, push, pull, merge, rebase - all from intuitive menus
- See your repo status at a glance
📋 Requirements
- Git installed on your system
- Doom Emacs with Magit enabled (included by default)
- Working inside a Git repository
⌨️ Opening Magit
Main Magit Interface:
SPC g g- Magit status (your main command!)SPC g d- Magit file dispatchSPC g f- Magit file commandsSPC g l- Magit logSPC g b- Magit blame
🎯 The Magit Status Buffer (Your Command Center)
Navigation:
j/korn/p- Move up/down between sectionsTAB- Expand/collapse section under cursorM-TAB- Expand/collapse all sectionsg- Refresh status buffer
Section Overview:
Untracked files - Files not in Git
Unstaged changes - Modified files not staged
Staged changes - Files ready to commit
Recent commits - Your commit history
Stashes - Your saved work-in-progress
📝 Staging & Unstaging
Stage Files:
s- Stage file/hunk under cursorS- Stage all unstaged changesi- Ignore file (add to .gitignore)
Unstage Files:
u- Unstage file/hunk under cursorU- Unstage all staged changes
Discard Changes:
k- Discard changes in file/hunk under cursorK- Discard all changes in working directory
Staging Hunks & Lines:
RETorSPC- Show diff of file under cursor- In diff view:
s- Stage hunk under cursoru- Unstage hunk under cursork- Discard hunk under cursor+/-- Show more/less context lines
💾 Committing
Create Commits:
c c- Commit (opens commit message buffer)c a- Amend last commitc e- Extend last commit (no message change)c w- Reword last commit messagec f- Fixup commitc s- Squash commit
In Commit Message Buffer:
C-c C-c- Finish commitC-c C-k- Cancel commitM-p/M-n- Previous/next commit message from history
🌿 Branching & Switching
Branch Operations:
b b- Switch branch (checkout)b c- Create new branchb n- Create branch from current HEADb s- Create branch and switch to itb r- Rename branchb k- Delete branch
Remote Branches:
b a- Set upstream for current branchb u- Set upstream and push
🔄 Remote Operations
Fetch & Pull:
f f- Fetch from default remotef a- Fetch from all remotesF F- Pull from upstreamF u- Pull from upstream (rebase)
Push:
P P- Push to upstreamP u- Push and set upstreamP f- Force push (use carefully!)P t- Push tags
📚 Viewing History & Logs
Log Views:
l l- Show log for current branchl o- Show log for other branchesl h- Show log for HEADl a- Show log for all branchesl f- Show log for file under cursor
In Log View:
RET- Show commit detailsd d- Show diff for commitc c- Create new commitr r- Revert commit
🔍 Diffs & Comparisons
Diff Commands:
d d- Diff working directory vs stagedd s- Diff staged vs HEADd u- Diff unstaged changesd r- Diff range between commits
In Diff Views:
j/k- Navigate between hunksn/p- Next/previous fileTAB- Toggle visibility of diff section+/-- Increase/decrease context lines
🔧 Rebasing & Merging
Merge:
m m- Merge branchm a- Abort mergem c- Continue merge
Rebase:
r i- Interactive rebaser r- Rebase branchr a- Abort rebaser c- Continue rebase
During Interactive Rebase:
j/k- Move between commitsp- Pick commit (default)r- Reword commit messagee- Edit commits- Squash commitf- Fixup commitd- Drop commit
📦 Stashing
Stash Operations:
z z- Stash current changesz i- Stash with messagez a- Apply stashz p- Pop stash (apply and delete)z k- Drop stashz l- List stashes
🏷️ Tags
Tag Operations:
t t- Create tagt a- Create annotated tagt k- Delete tagt p- Push tag
⚡ Pro Tips & Workflows
Daily Git Workflow:
SPC g g- Open Magit status- Review changes, stage with
s c c- Commit changesP P- Push to remote
Power User Tricks:
- Use
M-x magit-find-fileto quickly open files from Git history SPC g f s- Stage current file without opening MagitSPC g f u- Unstage current fileSPC g f d- Show file diff
Staging Granularity:
- Stage entire files with
sin status buffer - Stage individual hunks by entering diff view (
RET) thens - Stage individual lines by selecting region in diff then
s
Commit Best Practices:
- Use
c cfor normal commits - Use
c ato fix up your last commit - Use
c fto create fixup commits for interactive rebase later
🔧 Troubleshooting
Common Issues:
- Magit won't open? Make sure you're in a Git repository
- Performance slow? Try
M-x magit-refreshor restart Emacs - Merge conflicts? Magit highlights conflicts - resolve them and use
m c
Getting Help:
?- Show help in any Magit bufferC-h m- Show mode helpSPC h d m magit- Full Magit documentation
🚀 Quick Start Workflow
- Navigate to your Git repo in Doom Emacs
- Press
SPC g g- Opens Magit status - Stage files with
s, review diffs withRET - Commit with
c c, write message, finish withC-c C-c - Push with
P P
📚 Essential Keybind Summary
| Action | Key | Description |
|---|---|---|
| Status | SPC g g |
Open Magit status |
| Stage | s |
Stage file/hunk |
| Unstage | u |
Unstage file/hunk |
| Commit | c c |
Create commit |
| Push | P P |
Push to upstream |
| Pull | F F |
Pull from upstream |
| Branch | b b |
Switch branch |
| Log | l l |
Show log |
| Diff | d d |
Show diff |
| Stash | z z |
Stash changes |
| Help | ? |
Show context help |
🎉 Why Magit is Amazing
- Visual: See your entire repo state at a glance
- Interactive: Stage hunks, lines, or files with simple keystrokes
- Fast: Navigate Git operations faster than any CLI
- Powerful: Access every Git feature through intuitive menus
- Integrated: Works seamlessly with Doom Emacs and Evil mode
Pro Tip: Once you learn Magit, you'll never want to use Git from the command line again! 🚀