2026.07.13(月) / 09:49
ローカル環境のディレクトリでどのリモートと紐づいているか確かめる方法を教えてください
- ID
- 40025
- Published
- 2026-07-13 09:49
- Modified
- 2026-07-13 09:53
- Author
- khiro
- Categories
- デフォルト
- Tags
- Git
ローカル環境の対象ディレクトリに移動して、以下を実行します。
git remote -v
例:
origin git@github.com:username/my-portfolio.git (fetch)
origin git@github.com:username/my-portfolio.git (push)
この場合、ローカルのGitリポジトリは、GitHub上の
git@github.com:username/my-portfolio.git
と紐づいています。
origin のURLだけ確認するなら、こちらです。
git remote get-url origin
HTTPS接続の場合は、次のように表示されます。
https://github.com/username/my-portfolio.git
現在のブランチが、リモートのどのブランチを追跡しているか確認するには:
git branch -vv
例:
* main abc1234 [origin/main] 最新のコミット
これは、ローカルの main ブランチが、リモートの origin/main と紐づいているという意味です。
一通り確認するなら、この3つで十分です。
pwd
git remote -v
git branch -vv
なお、次のエラーが出た場合、そのディレクトリはGitリポジトリではありません。
fatal: not a git repository
その場合は、プロジェクト内に .git があるか確認します。
ls -la
git remote -v
hiroki@shibatahiroshitakanoiMac python % git remote -v
origin https://github.com/ki-hi-ro/python.git (fetch)
origin https://github.com/ki-hi-ro/python.git (push)
git remote get-url origin
hiroki@shibatahiroshitakanoiMac python % git remote get-url origin
https://github.com/ki-hi-ro/python.git
git branch -vv
hiroki@shibatahiroshitakanoiMac python % git branch -vv
- main adf375d [origin/main] for … else