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