git open opens the Git repository in the web browser.
Open the root of a repository.
$ git openOpen a specific file or folder of a repository.
$ git open main.goOpen a specific commit of a repository.
$ git open 7605d91Open a specific line, or range of lines, of a file.
$ git open main.go:42
$ git open main.go:42-50Open a different repository than cwd.
$ git -C ~/src/my-repo openBy default, four providers are supported: github.com, gitlab.com, bitbucket.org and codeberg.org.
| Provider | URL | Commit prefix | Path prefix | Line format |
|---|---|---|---|---|
| GitHub | https://github.com |
commit |
tree |
L%l-L%l |
| GitLab | https://gitlab.com |
-/commit |
-/tree |
L%l-%l |
| Bitbucket | https://bitbucket.org |
commits |
src |
lines-%l:%l |
| Codeberg | https://codeberg.org |
commit |
tree |
L%l-L%l |
To add custom Git providers and their URLs, set their values within the global git config.
[open "https://git.mydomain.dev"]
commitprefix = commit
pathprefix = tree
lineformat = L%l-L%lThis can also be set using the git CLI.
$ git config --global open.https://git.mydomain.dev.commitprefix commit
$ git config --global open.https://git.mydomain.dev.pathprefix tree
$ git config --global open.https://git.mydomain.dev.lineformat "L%l-L%l"commitprefix and pathprefix are used to template the URI for your provider.
fmt.Println(host + "/" + repository + "/" + commitprefix )
// https://git.mydomain.dev/<repository>/commit
fmt.Println(host + "/" + repository + "/" + pathprefix )
// https://git.mydomain.dev/<repository>/treelineformat templates the line anchor where %l denotes the line number. Up to two
%l may be provided, denoting the start and end lines. 3 or more %l or unsupported
Go-style verbs like %v will disable the line anchor templating and issue a warning.
fmt.Sprintf(lineformat, startLine) // one %l
fmt.Sprintf(lineformat, startLine, endLine) // two %l
// L42 or L42-L50Install with brew.
$ brew install arbourd/tap/git-openInstall with go install.
$ go install github.com/arbourd/git-open@latest