LoginSignup
11
8

More than 3 years have passed since last update.

Mac GitHubのリモートリポジトリをブラウザで開く便利コマンド

Last updated at Posted at 2019-09-29

GitHubのURLをコマンドですぐ開けたら便利だなと思って調べてみました。
方法としては open コマンドと hub コマンドを使う場合の二通りあります。

1. openコマンド

HTTPSプロトコルの場合

open $(git config remote.origin.url)

シンプルに書けます。

SSHプロトコルの場合

open https://github.$(git config remote.origin.url | cut -f2 -d. | tr ':' /)

SSHプロトコルでリモートリポジトリを設定していると git@github.com: から始まるので置換してます。また、HTTPSプロトコルでもこのコマンドはそのまま使えます。

alias設定

~/.bash_profile 等に下記コードを追記します。

alias gh="open https://github.$(git config remote.origin.url | cut -f2 -d. | tr ':' /)"

2. hubコマンド

hubコマンドをインストールします。

brew install hub

hub browse コマンドでGitHubのリモートリポジトリのURL

hub browse

参考

関連記事

11
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
8