首页·终端命令

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