Skip to content

Instantly share code, notes, and snippets.

@dotemacs
Created June 9, 2014 18:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dotemacs/9a0433341e75e01461c9 to your computer and use it in GitHub Desktop.
Save dotemacs/9a0433341e75e01461c9 to your computer and use it in GitHub Desktop.
Open remote repo in browser

Open remote repo

(defun parse-url (url)
  "convert a git remote location as a HTTP URL"
  (if (string-match "^http" url)
      url
    (replace-regexp-in-string "\\(.*\\)@\\(.*\\):\\(.*\\)\\(\\.git?\\)"
                              "https://\\2/\\3"
                              url)))
(defun magit-open-repo ()
  "open remote repo URL"
  (interactive)
  (let ((url (magit-get "remote" "origin" "url")))
    (progn
      (browse-url (parse-url url))
      (message "opening repo %s" url))))


(add-hook 'magit-mode-hook
          (lambda ()
            (local-set-key (kbd "o") 'magit-open-repo)))
@arthurcgusmao
Copy link

Thanks! Quite useful. I have created a more sophisticated function that also opens the current file or directory in the remote location automatically, may be of interest. (Link to commit)

@dotemacs
Copy link
Author

Cool thanks :)

@mpas
Copy link

mpas commented Mar 25, 2021

Thanks a lot!

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