I use this function to get the emacs dev version. (defun emacs-version-dev (here) "Display emacs build info and also save it to the kill-ring. If HERE is non-nil, also insert the string at point." (interactive "P") (let ((emacs-build-info (concat "Emacs version: " (emacs-version) "," " built using commit " emacs-repository-version ".\n\n" "./configure options:\n " system-configuration-options "\n\n" "Features:\n " system-configuration-features "\n"))) (kill-new emacs-build-info) (message emacs-build-info) (when here (insert emacs-build-info)) emacs-build-info)) AFAIK there is no definitive way to get the branch name because branches are ephemeral. But the below hack works for me. (defvar emacs-git-branch (when (and emacs-repository-version (file-exists-p source-directory)) (let ((shell-return (replace-regexp-in-string "[\n)]" " " ; Replace newline and ) chars with spaces (shell-command-to-string (concat "cd " source-directory " && " "git branch --contains " emacs-repository-version))))) ;; Below regexp is tested for following "git branch --contains" values ;; Output for a commit in master branch too ;; "* (HEAD detached at origin/emacs-25) ;; master ;; " ;; Output for a commit only in emacs-25 branch ;; "* (HEAD detached at origin/emacs-25) ;; " ;; (message "%S" shell-return) (string-match ".*[/ ]\\([^ ]+?\\)\\s-*$" shell-return) (match-string-no-properties 1 shell-return))) "Name of git branch from which the current emacs is built.") https://github.com/kaushalmodi/.emacs.d/blob/master/setup-files/setup-misc.el -- -- Kaushal Modi