Skip to content

jonathanchu/magit-gh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

magit-gh

https://melpa.org/packages/magit-gh-badge.svg

magit-gh is an Emacs package that integrates the GitHub CLI (gh) into Magit. It provides a Transient menu interface to list, checkout, and view pull requests directly from Emacs without leaving your workflow.

Features include:

  • List pull requests in a dedicated buffer with review status (toggle between open, closed, merged, and all)
  • PR status dashboard showing PRs you created, PRs awaiting your review, and recently merged PRs
  • PR checks/CI status with color-coded pass/fail/pending results
  • GitHub Actions workflow runs with status, workflow, branch, and event info
  • View a PR diff in a dedicated buffer
  • Checkout a PR branch with a single keystroke
  • Create a new pull request (opens GitHub in the browser)
  • View a PR in the browser

Why not Forge?

Forge is a fantastic and comprehensive package for interacting with Git forges from within Magit. If you need deep integration – tracking issues, managing pull requests, reading and writing comments, all stored locally – Forge is the right tool. I would highly recommend Forge over this package if that is your use case.

magit-gh takes a different approach. It delegates to the GitHub CLI (gh) for all GitHub interaction, which means:

  • No local database – Forge maintains a local SQLite database via emacsql, which can be tricky to set up (compiling native modules, resolving binary availability issues). magit-gh stores nothing locally.
  • No token management – Forge requires a GitHub personal access token stored in your authinfo file (ideally encrypted with GPG). magit-gh piggybacks on gh auth login, which you may have already configured.
  • Minimal dependencies – just Magit, Transient, and the gh CLI.

The trade-off is that magit-gh is far less featureful than Forge. It’s intentionally a lightweight alternative for users who primarily want to list, checkout, and view pull requests without additional setup overhead.

Requirements

  • Emacs 29.1+ (may work on older versions, this minimum version is what I’ve tested at least)
  • Magit 4.0.0+
  • Transient 0.5.0+
  • gh CLI (installed separately, must be authenticated via gh auth login)

Installing gh CLI

macOS

brew install gh

Linux (Fedora / RHEL / CentOS)

sudo dnf install gh

For other operating systems, see the official installation instructions.

Authenticate

After installing, authenticate with your GitHub account:

gh auth login

Installation

Install from MELPA:

M-x package-install RET magit-gh RET

Or with use-package:

(use-package magit-gh
  :ensure t
  :after magit)

Usage

You can access magit-gh from the Magit status menu by typing , or m-x magit-gh.

If you don’t like the , key binding to invoke magit-gh, you can set any custom value you want. Note that the variable must be set before the package loads:

(use-package magit-gh
  :ensure t
  :after magit
  :init
  (setq magit-gh-key ";")) ; Example setting key to ";" instead of the default ","

To increase the number of PRs fetched (default 30):

(use-package magit-gh
  :ensure t
  :after magit
  :custom
  (magit-gh-pr-limit 50))

The Transient menu is organized into Pull Request commands:

magit-gh
├── Overview
│   ├── l  List PRs
│   └── s  PR status dashboard
├── Inspect
│   ├── d  Diff PR
│   ├── k  PR checks/CI status
│   └── a  Actions (workflow runs)
└── Actions
    ├── c  Checkout PR
    ├── w  Create PR (web)
    └── v  View PR in browser

PR List Buffer

When you list PRs (l), a dedicated buffer opens showing PR number, age, title, author, review status, and branch name. By default it shows open PRs, but you can toggle the state filter with t to cycle through open, closed, merged, and all. The following keybindings are available in this buffer:

KeyAction
nMove to next PR
pMove to previous PR
RETCheckout the PR at point
cCheckout the PR at point
dView the diff for the PR at point
vOpen the PR at point in browser
kView CI checks for the PR at point
tToggle state (open/closed/merged/all)
gRefresh the PR list
qClose the buffer

PR Status Dashboard

The status dashboard (s) shows an overview of your PRs, mirroring gh pr status. It displays three sections: PRs you created, PRs awaiting your review, and recently merged PRs in the repository. All sections show an age column (days since creation), and the “Recently merged” section adds a merged column showing time since merge. The following keybindings are available in this buffer:

KeyAction
nMove to next PR
pMove to previous PR
RETCheckout the PR at point
cCheckout the PR at point
dView the diff for the PR at point
vOpen the PR at point in browser
kView CI checks for the PR at point
gRefresh the status dashboard
qClose the buffer

PR Checks

View CI check results for a PR (k) in a dedicated buffer. Press k from the transient menu to see checks for the current branch’s PR, or k on a PR row in the list or status buffers. Checks are sorted with failures first, and status is color-coded (green for pass, red for fail, yellow for pending). The following keybindings are available in this buffer:

KeyAction
nMove to next check
pMove to previous check
vOpen the check’s URL in browser
gRefresh the checks
qClose the buffer

Actions

View GitHub Actions workflow runs (a) in a dedicated buffer. Shows recent runs across the repository with status, workflow name, branch, event trigger, and age. Status is color-coded (green for success, red for failure/cancelled, yellow for in-progress/queued). The following keybindings are available in this buffer:

KeyAction
nMove to next run
pMove to previous run
vOpen the run in browser
gRefresh the runs
qClose the buffer

Demo

https://raw.githubusercontent.com/jonathanchu/magit-gh/refs/heads/main/screenshots/20260221_magit_gh_demo.gif

Customization

VariableDefaultDescription
magit-gh-key,Key to bind magit-gh in Magit buffers
magit-gh-pr-limit30Maximum number of PRs to fetch

Feature Status

  • [X] List pull requests (open, closed, merged, all)
  • [X] Checkout a pull request
  • [X] View a pull request in the browser
  • [X] View PR diff
  • [X] PR status dashboard (created by you, review requested, recently merged)
  • [X] Age and merged columns in PR tables
  • [X] PR checks/CI status
  • [X] Create a new pull request
  • [X] View and monitor workflow runs

Note: This feature set represents the 1.0 release. I consider the current scope complete and intentionally avoid overlapping with Forge features. If you have ideas for additional functionality, please open an issue to discuss.

Contributing

Contributions are welcome! If you’d like to help integrate additional gh CLI commands or improve existing functionality, please open a pull request.

Before submitting a PR, please keep in mind that this package is intended to extend Magit with useful GitHub CLI functionality – not to duplicate what Magit already provides. If you’re unsure whether a command is a good fit, feel free to open an issue to discuss it first.

To report bugs or request features, please use the GitHub issue tracker.

About

A lightweight GitHub CLI (gh) integration for Magit

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors