git push
git
書き方
git push [-u] [--force-with-lease] <remote> <branch>自分のコミットをリモートへ送ります。--forceはリモートのブランチを上書きして他人のコミットまで消しかねないので、リモートが動いていたら拒否する--force-with-leaseを使います。
よく使うオプション
| オプション | 意味 |
|---|---|
| -u | set the upstream so later pushes need no arguments |
| --force-with-lease | force, but stop if the remote moved since your last fetch |
| -f | force: overwrite the remote branch, commits of others included |
| --tags | push tags as well, which push does not do on its own |
| --delete <branch> | delete the branch on the server |
| --all | push every local branch |
| -n | dry run |
例
git push -u origin feature/loginpublishes the branch and remembers the pairing
git push --force-with-leasethe safe force, used after a rebase
git push origin --delete old-featureremoves the branch on the server
取り消しに何通りもあるのが混乱のもとです — ブランチの指す先を動かすのと、打ち消すコミットを積むのは別です。
読み方
- 角括弧 [ ] は省いてよい部分です。
- 三点 … は複数並べられるという意味です。
- オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。
よくある質問
Q. git push は何をしますか。
自分のコミットをリモートへ送ります。--forceはリモートのブランチを上書きして他人のコミットまで消しかねないので、リモートが動いていたら拒否する--force-with-leaseを使います。
Q. どう打ちますか。
git push [-u] [--force-with-lease] <remote> <branch> — 角括弧は省いてよい部分です。
Q. よく使うオプションはいくつですか。
ここにまとめたのは7個です。全部は man git にあります。このコマンドはgitの仲間です。
関連するコマンド
man ページ: man git-push