git push

git

書き方

git push [-u] [--force-with-lease] <remote> <branch>

自分のコミットをリモートへ送ります。--forceはリモートのブランチを上書きして他人のコミットまで消しかねないので、リモートが動いていたら拒否する--force-with-leaseを使います。

よく使うオプション

オプション意味
-uset the upstream so later pushes need no arguments
--force-with-leaseforce, but stop if the remote moved since your last fetch
-fforce: overwrite the remote branch, commits of others included
--tagspush tags as well, which push does not do on its own
--delete <branch>delete the branch on the server
--allpush every local branch
-ndry run

git push -u origin feature/login

publishes the branch and remembers the pairing

git push --force-with-lease

the safe force, used after a rebase

git push origin --delete old-feature

removes 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