Skip to content

Latest commit

 

History

66 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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
  • View repository information in a dedicated buffer
  • List an owner’s repositories
  • Fork, create, and sync repositories

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 and Repository 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
└── Repository
    ├── i  View repo info
    ├── L  List repos
    ├── o  Open repo in browser
    ├── f  Fork repo
    ├── n  New repo
    └── S  Sync repo

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

Repository Commands

The Repository group wraps the gh repo subcommands. Commands that can act on a repository other than the current one accept an optional [owner/]repo argument: invoke them with a prefix argument (C-u) to be prompted for a target, or run them directly to act on the current repository.

KeyAction
iView repo info (C-u for another repo)
LList an owner’s repositories
oOpen the repo in the browser (C-u for another repo)
fFork the current repo (opens a transient with fork options)
nCreate a new repository (opens a transient with repo options)
SSync a repository (choose: local clone or remote fork)

Notes:

  • View repo info (i) opens a dedicated buffer showing visibility, default branch, stars, forks, upstream (for forks), topics, and URLs.
  • List repos (L) opens a transient menu for listing repositories. Toggle filters for visibility, primary language, topic, forks vs. sources, archived state, and the result limit, then press the action key to read the owner (defaulting to the current repository’s owner) and display the results.
  • Fork (f) opens a transient menu for forking the current repository on GitHub. The menu heading shows the repository directory being forked, and forking asks for confirmation (naming the repository) first, so you always know which repository is targeted. By default the fork is created without cloning it or modifying your local git remotes. Toggle options to clone the fork, add a git remote (--remote, which sets the fork as origin and renames any existing origin to upstream), set the name of that remote, rename the fork, create it in an organization, or include only the default branch.
  • New repo (n) opens a transient menu for creating a repository. Choose the visibility (defaulting to private) and optionally set a description, home page, gitignore template, or license, and whether to clone the new repository or add a README. Pressing the action key prompts for the repository name (owner/name or just name).
  • Sync (S) prompts to choose between two distinct operations, rather than overloading a single argument like gh repo sync: sync local clone from upstream, which fast-forwards your local clone’s default branch from its parent and touches nothing on GitHub; and sync remote fork on GitHub, which updates your fork’s default branch on GitHub from its parent via the API. The remote sync needs push access, and the workflow token scope when the upstream changes include workflow files (run gh auth refresh -s workflow).

Repo Info Buffer

KeyAction
vOpen the repository in browser
oOpen the repository in browser
gRefresh the repository info
qClose the buffer

Repo List Buffer

KeyAction
nMove to next repository
pMove to previous repository
RETView info for the repository at point
vOpen the repository at point in browser
oOpen the repository at point in browser
gRefresh the repository list
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
magit-gh-repo-limit30Maximum number of repositories 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
  • [X] View repository information
  • [X] List an owner’s repositories
  • [X] Fork, create, and sync repositories

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

Stars

24 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages