Skip to content

Emacs Package: Magit

User-friendly interface for Git source control tool for many operations like:

  • Creating and amending commits
  • Managing and merging branches
  • Pulling from and pushing to remotes
  • Reading commit logs and “blaming” source files
  • Cherry—picking
  • Rebasing
  • Using the reflog

Not required when using Spacemacs

(use-package magit
:ensure

See Emacs Shortcuts for Magit - Emacs Shortcuts for Magit for common tasks.

  • Navigation:

    • Move forward/backward in sections: n and p
    • Move forward/backward in logical section (e.g. file, change) M-n and M-p
    • Move to parent section ^
  • Open transient Magit panel: ? - good way to learn all commands

Sources: How to use magit-list-repositories, git operations from magit-list-repositories

  • Use magit-list-repositories to view all repositories in a directory and perform operations on them.
  • With the above buffer, use magit-repolist-mode to perform operations on marked repositories like fetch with magit-repolist-fetch.

Magit diff, Checking Differences between branches

Section titled “Magit diff, Checking Differences between branches”

Source: local PR review, git worktrees, find breaking changes (go) - bashbunni YouTube

Use magit-diff and press e to see side by side changes of diff in context of the range selected.

Example process to check differences in branches:

  • Go into a feature branch
  • magit-diff-range, choose main branch
  • See diff
  • Choose diff and enter the file
  • magit-merge-preview to see changes like magit-diff-range