Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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 git@gitlab.com:{{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!

@mreishus

This comment has been minimized.

Copy link

mreishus commented Jun 7, 2020

(Removed comment about how I couldn't get this to work).
Make sure you use emacs to save the ~/.authinfo.gpg file - that way it will encrypt it for you. :)

@duchainer

This comment has been minimized.

Copy link

duchainer commented Jun 19, 2020

A big thanks to you! Been searching this for some time now ^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.