Skip to content

Instantly share code, notes, and snippets.

@Azeirah
Last active September 5, 2024 21:16
Show Gist options
  • Save Azeirah/542f1db12e3ef904abfc7e9c2e83310e to your computer and use it in GitHub Desktop.
Save Azeirah/542f1db12e3ef904abfc7e9c2e83310e to your computer and use it in GitHub Desktop.
Setting up magit forge for gitlab in Doom Emacs

Magit forge for Gitlab in Doom Emacs

This guide assumes you're working on a Unix-like environment. I'm using Linux Mint (Ubuntu). It should work on Macs, and might on Windows.

These are the four steps you can use as a checklist, see the headings below for the details on each step.

  • Enable forge support
  • Create a Gitlab API key
  • Add your gitlab credentials to ~/.authinfo.gpg
  • Set-up forge in emacs

Enable forge support

First, enable forge support in doom. Go to ~/.doom.d/init.el, and replace the magit module with (magit +forge).

For clarity, it should look somewhat like this

       lsp
       ;;macos             ; MacOS-specific commands
       (magit +forge)      ; a git porcelain for Emacs
       ;;make              ; run make tasks from Emacs
       ;;pass              ; password manager for nerds

You'll have to run doom sync and restart emacs. In emacs, you can use M-x doom/reload or <SPC h r r>

Create a Gitlab API key

Create a Gitlab API key for the account you'll be using to access your repositories, write this one down. I'm not entirely sure what rights you should give the repo, but I gave it all read rights, and write rights to the repository itself.

Add your gitlab credentials to ~/.authinfo.gpg

Edit or create the file ~/.authinfo.gpg. If it's new, paste the following. Fill in your email address, your gitlab username and your api key where the {{LOUD-BRACKETS}} are.

# -*- epa-file-encrypt-to: ("{{YOUR-EMAIL-ADDRESS}}") -*-
machine gitlab.com/api/v4 login {{YOUR-GITLAB-USERNAME}}^forge password {{YOUR-API-KEY}}

NOTE THE NEWLINE AT THE END, the authinfo format is very sensitive.

Set-up forge in emacs

In emacs, open a magit buffer for a or the repo you want to use forge with. Run the command M-x forge-add-repository. Note, if you have a remote named origin (as is the convention) in this repository, forge will automatically fill in the right info. If you don't, you'll have to type in the remote yourself. IE [email protected]:{{your-user}}/{{your-repo}}

Run forge commands right from Magit

In a Magit buffer, press @ (discover via the popup of popups with ?). This will list all available forge commands. You can now list issues, create issues, and lots more, yay!

@kassick
Copy link

kassick commented May 22, 2024

I had to add machine {{HOST}}api/v4 login {{USER}}^forge secret {{API_KEY}} to authrc for forge to work with my gitlab instance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment