{"slug": "custom-git-trailers-with-magit", "title": "Custom Git Trailers with Magit", "summary": "A new Emacs Lisp configuration lets Magit users insert an \"Assisted-by\" commit trailer to credit AI coding agents, prompted via the transient menu at C-c TAB with completion history. The snippet, published as a HOWTO, appends the trailer using Magit's private git-commit--insert-trailer function and registers the token for font-lock, with an optional savehist setup to persist entered values across sessions.", "body_md": "Git trailers are just lines of text at the bottom of a commit that take note of some\nmetadata. Common ones are `Co-Authored-By`\n\n, `Reported-By`\n\n, `Reviewed-By`\n\nor\n`Signed-Off-By`\n\n, all of them autodescriptive I think.\n\nMagit has a way of adding trailers, just press `C-c TAB`\n\nor `C-c C-i`\n\nin commit\nview. Magit will then display a transient menu with some options:\n\nNowadays it's becoming commonplace to use the [ Assisted-by:\ntrailer](https://github.com/microsoft/vscode/issues/313962) to credit AI coding agents,\nand I wanted to start using it as I'm doing most of my coding with AI support now.\nMagit doesn't support this trailer (yet!), but I had my AI figure out how to add it.\n\nIn this small HOWTO I will show you how to add a new kind of commit trailer to Magit, so\nit will be just a `C-c TAB`\n\naway. I will use the `Assisted-by`\n\nexample, but you can\ntweak it to anything you need. It prompts for a value (free text, e.g. `Kimi K3`\n\nor\n`venice/zai-org-glm-5-2`\n\n) and appends it to the commit buffer as `Assisted-by: <value>`\n\nafter any other existing trailers.\n\nIt remembers previously entered values, which are offered as completion. As a bonus I\nwill show how to configure Emacs' built-in `savehist`\n\npackage to persist that history\nacross Emacs sessions.\n\n## Magit config\n\n```\n(use-package magit\n  :preface\n  (defvar my-git-commit-assisted-history nil\n    \"History of values entered for `my-git-commit-assisted'.\")\n  (defun my-git-commit-assisted ()\n    \"Insert an \\\"Assisted-by\\\" trailer crediting an AI coding agent.\nPrompt for the agent description (free text, e.g. \\\"Claude Opus 4.7\\\"),\noffering previously entered values as completion.\"\n    (interactive)\n    (let ((value (completing-read \"Assisted by: \"\n                                  my-git-commit-assisted-history\n                                  nil nil nil\n                                  'my-git-commit-assisted-history)))\n      (when (string-empty-p value)\n        (user-error \"Empty agent description\"))\n      ;; NOTE: `git-commit--insert-trailer' is a private API; magit\n      ;; offers no public function for inserting an arbitrary trailer.\n      (git-commit--insert-trailer \"Assisted-by\" value)))\n  :config\n  ;; C-c TAB A or C-c C-i A inserts the trailer\n  (transient-append-suffix 'git-commit-insert-trailer 'git-commit-test\n                           '(\"A\" \"Assisted\" my-git-commit-assisted))\n  (add-to-list 'git-commit-trailers \"Assisted-by\"))\n```\n\nHow it works:\n\n`transient-append-suffix`\n\nappends the command to`git-commit-insert-trailer`\n\n(`C-c TAB`\n\n) right after the built-in \"Co-developed\" entry, so it shows up as`A`\n\nin the trailer menu.- Prompt for the value happens by\n`completing-read`\n\nin the minibuffer, so you get your configured completion system (I use[vertico](https://github.com/minad/vertico)) to pick among the candidates, or input free text. - Insertion goes through the same internal helper magit uses for\n`Signed-off-by`\n\n, so the trailer lands after existing trailers and before the comment/diff section regardless of buffer layout. - Adding\n`\"Assisted-by\"`\n\nto`git-commit-trailers`\n\nmakes the token font-lock like the built-in ones. This is needed because values are free text; magit only highlights arbitrary tokens when they have the`Name <email>`\n\nshape. - A note for old Magit users: the trailer menu used to be\n`git-commit-insert-pseudo-header`\n\n; it is now an obsolete alias for`git-commit-insert-trailer`\n\n.\n\n## Bonus: remember values across sessions with savehist\n\nOut of the box the completion history dies with the Emacs session, which is unfortunate\nbecause most of the time we will be entering the same values again and again. By\nenabling `savehist-mode`\n\n, every minibuffer history variable is saved automatically once\nused — this history included — so often *nothing extra is needed besides having the mode\nenabled*. If you'd rather state the intent explicitly (or you save only a whitelist by\nsetting `savehist-save-minibuffer-history`\n\nto `nil`\n\n), register it:\n\n```\n(use-package savehist\n  :config\n  (setq savehist-additional-variables\n        '(my-git-commit-assisted-history))\n  (savehist-mode +1))\n```\n\nOrdering matters: `savehist-mode`\n\nrestores once when enabling it, so if you put it\nbefore setting `savehist-additional-variables`\n\nthen you would see the new variables\n(`my-git-commit-assisted-history`\n\nin my case) get stored in the `savehist`\n\nfile, but\nthey would not be restored when Emacs starts again. Ask me how I know.\n\n## Closing thoughts\n\nI dislike having to use a private var like `git-commit--insert-trailer`\n\n, it's something\nthat might break at any point. But I'm OK with it because it's very localized and in a\nnon-critical functionality that I won't mind if it ever breaks. If it happens I will\nremember to update this post.\n\nAbout `Assisted-by`\n\n, I plan on using it extensively, I want to be very honest about my\nAI use.\n\nAre you using `Assisted-by`\n\nor other commit trailers?", "url": "https://wpnews.pro/news/custom-git-trailers-with-magit", "canonical_source": "https://blog.fidelramos.net/software/emacs-custom-magit-trailers", "published_at": "2026-08-12 20:42:11+00:00", "updated_at": "2026-08-12 21:14:46.709517+00:00", "lang": "en", "topics": ["developer-tools"], "entities": ["Magit", "Emacs", "savehist", "vertico", "Kimi K3", "venice/zai-org-glm-5-2"], "alternates": {"html": "https://wpnews.pro/news/custom-git-trailers-with-magit", "markdown": "https://wpnews.pro/news/custom-git-trailers-with-magit.md", "text": "https://wpnews.pro/news/custom-git-trailers-with-magit.txt", "jsonld": "https://wpnews.pro/news/custom-git-trailers-with-magit.jsonld"}}