新建project,然后本地进入一个文件1111,然后开始关联本地和远程:
Create a new repositorygit clone git@gitlab.tools.vipshop.com:anita.fang/11111.gitcd 11111touch README.mdgit add README.mdgit commit -m "add README"git push -u origin master
Existing folder or Git repositorycd existing_foldergit initgit remote add origin git@gitlab.tools.vipshop.com:anita.fang/11111.gitgit add .git commitgit push -u origin master
这样就新建了一个master分支,然后再建立一个新的分支
1 查看远程分支
$ git branch -a* br-2.1.2.2 master remotes/origin/HEAD -> origin/master remotes/origin/br-2.1.2.1 remotes/origin/br-2.1.2.2 remotes/origin/br-2.1.3 remotes/origin/master
2 查看本地分支
$ git branch* br-2.1.2.2 master
3 创建分支
shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei (br-2.1.2.2)$ git branch testshuohailhl@SHUOHAILHL-PC /f/ggg/jingwei (br-2.1.2.2)$ git branch* br-2.1.2.2 master test #线面是把分支推到远程分支 git push origin test
4 切换分支到test
shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei (br-2.1.2.2)$ git branch* br-2.1.2.2 master testshuohailhl@SHUOHAILHL-PC /f/ggg/jingwei (br-2.1.2.2)$ git checkout testM jingwei-server/src/main/java/com/taobao/jingwei/server/service/cmd/GetCustomerTarCmd.javaM jingwei-server/src/main/java/com/taobao/jingwei/server/util/ServerUtil.javaSwitched to branch 'test'shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei (test)$ git branch br-2.1.2.2 master* test
M 表示cong 原来分支(上一次修改没有提交br-2.1.2.2)带过来的修改
5 删除本地分支 git branch -d xxxxx
shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei (test)
$ git checkout br-2.1.2.2M jingwei-server/src/main/java/com/taobao/jingwei/server/service/cmd/GetCustomerTarCmd.javaM jingwei-server/src/main/java/com/taobao/jingwei/server/util/ServerUtil.javaSwitched to branch 'br-2.1.2.2'shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei (br-2.1.2.2)$ git br* br-2.1.2.2 master testshuohailhl@SHUOHAILHL-PC /f/ggg/jingwei (br-2.1.2.2)$ git br -d testDeleted branch test (was 17d28d9).shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei (br-2.1.2.2)$ git br* br-2.1.2.2 master
6 查看本地和远程分支 -a。前面带*号的代表你当前工作目录所处的分支
remotes/origin/HEAD -> origin/master #啥意思呢?
”在clone完成之后,Git 会自动为你将此远程仓库命名为origin(origin只相当于一个别名,运行git remote –v或者查看.git/config可以看到origin的含义),并下载其中所有的数据,建立一个指向它的master 分支的指针,我们用(远程仓库名)/(分支名) 这样的形式表示远程分支,所以origin/master指向的是一个remote branch(从那个branch我们clone数据到本地)“
这个是执行 git remote -v 的结果,看出来origin其实就是远程的git地址的一个别名。
$ git remote -vorigin git@xxxx/jingwei.git (fetch)origin git@xxxx/jingwei.git (push)
shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei (test)$ git branch -a br-2.1.2.2 master* test remotes/origin/HEAD -> origin/master remotes/origin/br-2.1.2.1 remotes/origin/br-2.1.2.2 remotes/origin/br-2.1.3 remotes/origin/master
7 删除远程版本
git push origin :br-1.0.0
在新建分支的时候,新建的分支会copy master分支里面的数据,这样就需要先删除master分支的数据,对于删除远程仓库的文件操作如下:
首先要明确,git rm只能删除本地文件,要是想删除远端文件的话,只能拿本地文件进行覆盖。
先删除本地文件,然后把本地文件同步到远程;
git add . git commit -am "###" -------以上3步只是本地提交 git push origin 本地分支:远程分支