git push 命令

Post on Jan 20, 2022 by Wei Lin

git push—上传及合并

命令:git push <远程仓库名> <本地分支名>:<远程分支名>

命令:git push remoteRepo localBranch:remoteBranch

作用:将本地分支localBranch上传到远程仓库remoteRepo中与远程分支remoteBranch合并。

git push remoteRepo localBranch

说明:如果远程分支名被省略,则表示将本地分支localBranch推送到远程仓库remoteRepo。

注:远程分支名通常与本地分支名相同(均默认为master),如果该远程分支不存在,则会被新建。

image-20230727005015246


也可以用远程分支的url

image-20230727005037679

git push remoteRepo

说明:如果远程分支和本地分支均被省略,则表示将当前的本地分支推送到remoteRepo仓库的对应分支。

git push -d 删除远程分支

命令:git push -d rometeRepo RometeBranch

说明:同–delete,删除远程仓库RometeRepo中的分支RometeBranch

image-20230727005057229

git push -u 关联远程分支

命令:git push -u rometeRepo localBranch:remoteBranch

说明:同–set-upstream,将本地分支localBranch关联到远程仓库RometeRepo的remoteBranch分支中。

注:如果remoteBranch省略,则会默认关联到与本地分支同名的远程分支中。如果无该远程分支则会创建。

image-20230727005116733

git push remoteRepo HEAD:refs/for/remoteBranch

说明:将当前的本地分支推送到远程仓库remoteRepo的分支remoteBranch中,并且需要Code Review才能合并。

注:refs不是git中的规则,是gerrit中的规则。

说明:

  • <remote-name|url>是远程库的名字或url
  • HEAD: 表示一个特别的指针,指向你正在工作的本地分支的指针,可以当做是本地分支的别名。git通过它可以知道当前工作区间在哪个分支。
  • refs/for :表示我们提交代码到服务器之后是需要经过Code Review之后才能进行merge操作的,而refs/heads是不需要的。