git remote

git

書き方

git remote -v | git remote add <name> <url>

リモートリポジトリの名前と場所を扱います。記録するだけなので、addやset-urlをしてもfetchやpushをするまで何も行き来しません。

よく使うオプション

オプション意味
-vlist the remotes with their URLs
add <name> <url>register another repository
set-url <name> <url>point an existing remote somewhere else
rename <old> <new>rename a remote
remove <name>forget a remote
show <name>branches it has and how they are tracked
prune <name>drop tracking refs for branches deleted there

git remote -v

shows the fetch and push URL of every remote

git remote add upstream https://github.com/orig/repo.git

adds the original repo alongside your fork

git remote set-url origin git@github.com:me/repo.git

switches origin from HTTPS to ssh

取り消しに何通りもあるのが混乱のもとです — ブランチの指す先を動かすのと、打ち消すコミットを積むのは別です。

読み方

  • 角括弧 [ ] は省いてよい部分です。
  • 三点 … は複数並べられるという意味です。
  • オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。

よくある質問

Q. git remote は何をしますか。

リモートリポジトリの名前と場所を扱います。記録するだけなので、addやset-urlをしてもfetchやpushをするまで何も行き来しません。

Q. どう打ちますか。

git remote -v | git remote add <name> <url> — 角括弧は省いてよい部分です。

Q. よく使うオプションはいくつですか。

ここにまとめたのは7個です。全部は man git にあります。このコマンドはgitの仲間です。

関連するコマンド

man ページ: man git-remote