目的:从一个新文件夹中git一个远程仓库的代码
1,新建本地mster分支
首先是git bash here打开git窗口进行操作
进行仓库的初始化git init

但是这时候还没有分支,虽然会显示master,但是用
git branch -a

表示还没有分支
如果我们这时候新建分支test,就会报错,这是因为还没有master分支

这个时候,正确的操作方法是这样的,
首先,新建一个txt文件,随便建的,用来初始化git本地仓库

然后
git add .
git commit -m 'init'

这个时候在去 git branch 查看分支,就有 master 分支了

现在可以创建分支test
git branch test

切换分支
git checkout test

可以看到,已经切换过来了
2,本地仓库连接远程仓库
这里连接google的开源仓库作为示例
git remote add origin https://aomedia.googlesource.com/aom

查看一下远程仓库地址:
git remote -v

这时候已经连接上了远程仓库,但是我们需要fetch一下
git fetch
可能显示time out这里可能需要根据自己的fq软件看一下自己的端口号
git config --global http.proxy 127.0.0.1:自己使用的端口号
然后再git fetch

此时已经连接上远程仓库
这时查看远程仓库分支
git branch -a

3、关联远程分支
两种方法,
第一种 git reset --hard 分支名/commit号
这种方法直接将当前分支关联到远程分支,
第二种 git checkout -b 新分支名 远程分支名
这种是新建一个新的分支关联到远程分支
这里使用第一种

至此,远程分支代码已经拉取
网友评论