我在本地建了一个分支cocoli,开发完之后,提交代码:(代码1)
git add .
git commit -m '注释'
git push
意思是:当前分支没有与远程分支关联。因此导致了提交代码失败:
$ git push
fatal: The current branch wangxiao has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin cocoli
解决方案:
- 直接 git push origin cocoli 推向制定的分支,最强暴的方法
- 关联远程分支,代码如下:
git push --set-upstream origin cocoli
关联有一个好处,以后就不用每次git push都用代码1了
另外:git pull 时也会让其关联对应的远程分支
这种情况是:当你在自己电脑上开完一部分后,某一天在另一台什么也没有的电脑上开发,要把仓库下载下来时,git pull
就会让其设置要关联的远程分支是谁? 请移步我另一篇博客:::