2026-03-15

ターミナルから GitHub リポジトリをブラウザで開く

プログラミング

TL;DL

GitHub CLI を使うと以下のコマンドで GitHub リポジトリの URL を開ける。

1
$ gh browse

GitHub リポジトリの URL をターミナルから開く

ターミナル上で作業していると GitHub の URL を直ぐに開きたいことがある。そのような時は、GitHub であれば gh コマンド (GitHub CLI) を使うことで直接ブラウザで URL を開ける。

1
$ gh browse

これが機能する条件は、リモートリポジトリを設定していることだ。 GitHub をリモートリポジトとして使っているのであれば、基本的には以下のコマンドをリポジトリを作成したときに実行しているか、

1
$ git remote add origin {リモートリポジトリ}

先に GitHub 上でリポジトリを作成し、クローンしてきていると思うので設定されているだろう。リモートリポジトリが設定されているかは次のコマンドで確認できる。

1
$ git remote -v

何故この記事を書いたか

gh コマンドで GitHub リポジトリが開けたはずだけどサブコマンドは何だったかな?と思ってそれらしいキーワードでググってみたところ、一番シンプルな解決方法がヒットしなかった。

gh browse 以外の方法として、

  • git コマンドのエイリアス
  • bash/zsh のエイリアス
  • hub コマンドの hub browse
  • gh コマンドの repo サブコマンドを使った gh repo view --web

あたりがヒットする。昔は gh repo view --web 以外に方法がなかったのかもしれないが、現在は gh browse でリポジトリに限らず、 GitHub の様々なページをターミナル上から開ける。

そんなわけで、ターミナルから GitHub を開く方法を調べた人の知識のアップデートになればと思い記事に残しておく。

gh browse

1
$ gh browse --help
2
Transition from the terminal to the web browser to view and interact with:
3
4
- Issues
5
- Pull requests
6
- Repository content
7
- Repository home page
8
- Repository settings
9
10
11
USAGE
12
gh browse [<number> | <path> | <commit-sha>] [flags]
13
14
FLAGS
15
-a, --actions Open repository actions
16
-b, --branch string Select another branch by passing in the branch name
17
-c, --commit string[="last"] Select another commit by passing in the commit SHA, default is the last commit
18
-n, --no-browser Print destination URL instead of opening the browser
19
-p, --projects Open repository projects
20
-r, --releases Open repository releases
21
-R, --repo [HOST/]OWNER/REPO Select another repository using the [HOST/]OWNER/REPO format
22
-s, --settings Open repository settings
23
-w, --wiki Open repository wiki
24
25
INHERITED FLAGS
26
--help Show help for command
27
28
ARGUMENTS
29
A browser location can be specified using arguments in the following format:
30
- by number for issue or pull request, e.g. "123"; or
31
- by path for opening folders and files, e.g. "cmd/gh/main.go"; or
32
- by commit SHA
33
34
EXAMPLES
35
# Open the home page of the current repository
36
$ gh browse
37
38
# Open the script directory of the current repository
39
$ gh browse script/
40
41
# Open issue or pull request 217
42
$ gh browse 217
43
44
# Open commit page
45
$ gh browse 77507cd94ccafcf568f8560cfecde965fcfa63
46
47
# Open repository settings
48
$ gh browse --settings
49
50
# Open main.go at line 312
51
$ gh browse main.go:312
52
53
# Open main.go with the repository at head of bug-fix branch
54
$ gh browse main.go --branch bug-fix
55
56
# Open main.go with the repository at commit 775007cd
57
$ gh browse main.go --commit=77507cd94ccafcf568f8560cfecde965fcfa63
58
59
ENVIRONMENT VARIABLES
60
To configure a web browser other than the default, use the BROWSER environment variable.
61
62
LEARN MORE
63
Use `gh <command> <subcommand> --help` for more information about a command.
64
Read the manual at https://cli.github.com/manual
65
Learn about exit codes using `gh help exit-codes`
66
Learn about accessibility experiences using `gh help accessibility`
【改訂新版】Gitポケットリファレンス

【改訂新版】Gitポケットリファレンス

Amazon アソシエイトについて

この記事には Amazon アソシエイトのリンクが含まれています。Amazonのアソシエイトとして、SuzumiyaAoba は適格販売により収入を得ています。