I want to create a git alias
which will allow me to do git visit
and the repository will be opened in the browser.

- 1,809
- 1
- 5
- 22
7 Answers
When you type a command such as git xyz
, git looks for a file named git-xyz
and if found, it executes it. You can simulate such behavior by putting a file named git-visit
in a directory which is in the PATH
, and then git visit
will execute it.
The content of the file should be
xdg-open $(git remote -v | cut -d @ -f 2 | cut -d ' ' -f 1 | head -1 | sed 's/:/\//' | sed 's/.git$//' | sed s'/^/https:\/\//') >& /dev/null &
(xdg-open
might not work on your machine).
Note that you must do chmod +x git-xyz
in order to make the file executable

- 1,809
- 1
- 5
- 22
This works for me in Git for Windows with Git Bash. Place the following in your git configuration file:
[alias]
visit = "!git remote get-url origin | xargs -r start"
visitfancy = "!f() { REMOTE=${1:-origin}; URL=$(git remote get-url \"$REMOTE\"); if [[ -n \"$URL\" ]]; then start \"$URL\"; fi; }; f"
visit
will just launch the remote url of origin
if it exists.
visitfancy
will launch the remote url of the remote name you specify, or default to origin
if none is specified.

- 3,211
- 1
- 16
- 18
I am using the following:
[alias]
visit = "!f(){ xdg-open `git config --get remote.origin.url | sed -Ee 's#(git@|git://)#https://#' -e 's@com:@com/@'`| head -n1; }; f"
It works for SSH and HTTPS cloned repository + GitHub and GitLab

- 884
- 6
- 8
what I use on osx:
Use the desired browser by simply replacing Firefox.app
with eg. Safari.app
, Brave Browser.app
, Google Chrome.app
...
alias visit='open -a "/Applications/Firefox.app" $(git config --get remote.origin.url)'

- 558
- 5
- 11
On windows you can run the following command in your repo terminal:
start (git config --get remote.origin.url)

- 101
- 3