天天看点

Git创建分支并提交到远程分支

创建本地分支并提交到远程

  • 1. git branch -r 命令查看远端库的分支情况(其他分支就不列出来了)
    Git创建分支并提交到远程分支
  • 2.从已有的分支创建新的分支(如从develop分支),创建一个newneeds_0215分支
    Git创建分支并提交到远程分支
  • 3.我们git branch -a查看一下当前分支,发现已经切换过来了
    Git创建分支并提交到远程分支
  • 4.我们通过git push试图将本地分支推到远程,发现出现以下报错:
fatal: The current branch feature/newneeds_0215 has no upstream branch.
To push the current branch and set the remote as upstream, use

   git push --set-upstream origin feature/newneeds_0215
           
Git创建分支并提交到远程分支

问题的原因是没有将本地的分支与远程仓库的分支进行关联,远程有许多分支,不知道你到底想推到那个分支上去

  • 5.我们输入git push --set-upstream origin feature/newneeds_0215

    本地分支推到远程newneeds_0215分支上了,这时候我再git branch -r就可以看见远程newneeds_0215分支了