-
-
Notifications
You must be signed in to change notification settings - Fork 132
Tips and Tricks
Please add your tips and tricks here, or if you are unsure whether they are a good fit, first create a show & tell discussion.
Also see the list of show & tell discussions.
You might want to use gh: instead of having to type github.com/ over
and over again.
There are at least two methods to achieve that when using Git and Magit. Make sure to not combine the two approaches for the same host.
Regardless of what approach you chose, test with something like:
$ git clone gh:magit/forge
If that works, it should also work in Magit; without any Magit specific configuration.
(Before v0.4, Magit needed some extra configuration for the second approach
to work. If any entries remain in forge-alist, which reference an alias,
then please remove that.)
To refer to github.com as gh add to ~/.ssh/config:
Host gh
HostName github.com
User git
To refer to github.com as gh add to $XDG_CONFIG_HOME/git/config or
~/.gitconfig:
[url "[email protected]:"]
insteadOf = gh:
See git-clone(1) and git-config(1)#FILES.
Initially only secured forges (those using tls) were supported (because I assumed that nobody would forgo securing their gitlab and github instances).
The consequence is that in addition to the usual setup, you additionally have
to add the APIHOST and WEBHOST of the respective forge-alist entry to
ghub-insecure-hosts as well.
For example, for this forge-alist entry
("example.com" "example.com/api/v4" "www.example.com" forge-gitlab-repository)you have to add
(add-to-list 'ghub-insecure-hosts "example.com/api/v4")
(add-to-list 'ghub-insecure-hosts "www.example.com")To access a private forge through a zero-trust proxy, an additional access token
must be attached to requests. Assuming get-zero-trust-token is a function
that returns the appropriate token as a string, we can advise ghub--headers to
inject the access token:
(advice-add 'ghub--headers :around
(lambda (fn headers host auth username forge)
(funcall fn
(if-let* ((_(string-match-p "zero-trust\\.forge" host))
(token (get-zero-trust-token host)))
`(("access-token" . ,token) ,@headers)
headers)
host auth username forge)))Add this to your init to instruct emacs to use the secrets api (aka gnome passwords/keyring):
(setq auth-sources '("secrets:Login"))Also see Secret Service API.
You need to eval this after you set the auth source as above, to create a secret in the gnome keyring with the fields you want since you cannot do this from the UI:
(secrets-create-item "login" "Forge Github Token"
"YOUR_GITHUB_TOKEN_GOES_HERE"
:host "api.github.com"
:user "YOUR_USERNAME_GOES_HERE^forge")Taken from #462.