git push 操作

来源:互联网 发布:淘宝人气怎么刷 编辑:程序博客网 时间:2024/06/01 14:22

git push 的格式详见 这里。


之前 git push 的默认操作是matching:

all your branches were sent to the remote as long as there already are branches of the same name over there.


在新出的 Git-1.8.0 中提到在下个版本中(注意不是1.8.0)会将 git push 的默认操作设为simple:

We will use the "simple" semantics that pushes the current branch to the branch with the same name, only when the current branch is set to integrate with that remote branch.


强烈建议用 git push 时输入完整的命令,而不是简单的 git push,因为你不知道默认的 git push 到底会做什么意想不到的操作。

$ git push <repository> <refspec> …

如:提交本地test分支作为远程的master分支

$ git push origin test:master 

提交本地test分支作为远程的test分支

$ git push origin test:test

如果要删除远程的某个分支(test),把本地分支参数设为空,可以理解为把null推送到远程某个分支,远程分支不就没了。

$ git push origin :test

附:

强推,即利用强制覆盖的方式用本地的分支替代远程库中的分支,慎用:

$ git push -f origin test:test

设置 git push 的默认操作:

$ git config --global push.default upstream

(push 的操作方式有四种:nothing,matching,upstream,current。在Git 1.8.0中说到的会增加的simple方式,见release-note)


还有,有时候 git push 的时候出现这种错误:

$ git pushfatal: The current branch hotfix has no upstream branch.
这是没有指定当前分支跟踪的远程分支,所以git不知道要推送到哪,可以用git push --set-upstream设定:

$ git push --set-upstream origin hotfix...Branch hotfix set up to track remote branch hotfix from origin.



原创粉丝点击