1.在之前的分支工程目录下(举例分支为z3),
git checkout -b z3
此命令相当于:
git branch z3
git checkout z3

2.查看当前分支
git branch

它就会有如下显示:
  * z3
    master

3.给分支加入一个新的远程端
git remote add <远程端分支> <远程端地址>

name可以输入git remote 不带参数,列出已经存在的分支,例如

#git remote
 origin

本例子里面建立的分支z3, 命令为
git remote add z3 git@192.168.1.188:sprd6820.git

origin为<远程端分支>
git@192.168.1.188:sprd6820.git为<远程端地址>


4.将所有修改提交到你的分支上
git push origin z3

 


git pull push没有指定branch报错的解决方法
git 执行git push 和git pull的操作时候,经常看到下面的提示:

You asked me to pull without telling me which branch you
want to merge with, and 'branch.dev.merge' in
your configuration file does not tell me, either. Please
specify which branch you want to use on the command line and
try again (e.g. 'git pull <repository> <refspec>').
See git-pull(1) for details.

If you often merge with the same branch, you may want to
use something like the following in your configuration file:

[branch "dev"]
remote = <nickname>
merge = <remote-ref>

[remote "<nickname>"]
url = <url>
fetch = <refspec>

See git-config(1) for details.

 

在高版本的 git下面,也许会看见这样的提示:

There is no tracking information for the current branch.

Please specify which branch you want to merge with.

See git-pull(1) for details

git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with

git branch --set-upstream master origin/<branch>

看到第二个提示,我们现在知道了一种解决方案。也就是指定当前工作目录工作分支,跟远程的仓库,分支之间的链接关系。

比如我们设置z3对应远程仓库的z3分支

git branch --set-upstream z3 origin/z3

这样在我们每次想push或者pull的时候,只需要 输入git push 或者git pull即可。

在此之前,我们必须要指定想要push或者pull的远程分支。

git push origin z3

git pull origin z3.

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐