git fetch
git
書き方
git fetch [--all] [--prune] [<remote> [<branch>]]リモートの新しいコミットを受け取るだけで、自分のファイルやブランチは動きません。反映にはmergeやrebaseが必要で、サーバーで消えたブランチは--pruneまで残ります。
よく使うオプション
| オプション | 意味 |
|---|---|
| --all | from every remote |
| --prune | delete tracking refs whose branch is gone on the server |
| --tags | also fetch tags |
| --unshallow | fill in the history a --depth clone left out |
| --depth <n> | deepen a shallow clone by n commits |
| -f | update a ref even when it is not a fast-forward |
例
git fetch --all --prunerefreshes every remote and clears dead branches
git fetch origin mainupdates origin/main without touching your files
git fetch --unshallowturns a shallow clone into a full one
取り消しに何通りもあるのが混乱のもとです — ブランチの指す先を動かすのと、打ち消すコミットを積むのは別です。
読み方
- 角括弧 [ ] は省いてよい部分です。
- 三点 … は複数並べられるという意味です。
- オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。
よくある質問
Q. git fetch は何をしますか。
リモートの新しいコミットを受け取るだけで、自分のファイルやブランチは動きません。反映にはmergeやrebaseが必要で、サーバーで消えたブランチは--pruneまで残ります。
Q. どう打ちますか。
git fetch [--all] [--prune] [<remote> [<branch>]] — 角括弧は省いてよい部分です。
Q. よく使うオプションはいくつですか。
ここにまとめたのは6個です。全部は man git にあります。このコマンドはgitの仲間です。
関連するコマンド
man ページ: man git-fetch