企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
一、远程分支的基本操作 1、创建远程分支 第一种方法:将本地新建的分支直接推送到远程仓库,并且远程分支和本地分支建立关联咯 案例1:把本地分支Develop推送到远程仓库,并取名叫feature/Develop $ git branch -a Develop * gray-dev-m master remotes/origin/HEAD -> origin/master remotes/origin/gray-dev-m remotes/origin/master 将本地Develop推送到远程仓库 $ git push origin Develop:feature/Develop Total 0 (delta 0), reused 0 (delta 0) remote: remote: To create a merge request for feature/Develop, visit: remote: http://git.91als.net/root/yyg/merge_requests/new?merge_request%5Bsource_branch%5D=feature%2FDevelop remote: To git.91als.net:root/yyg.git * [new branch] Develop -> feature/Develop 说明: origin: 远程仓库 Develop: 本地分支 feature/Develop: 远程分支 查看gitlab上,发现多了一个分支,feature/Develop ![](https://box.kancloud.cn/d8744df0a9c6bbb148d8848f91793b56_1503x433.png) 在本地查看分支情况 ![](https://box.kancloud.cn/9dbe90c1e3f0fba8ab2b96117e5e304a_531x171.png) 案例2:把本地分支new推送到远程仓库,并取名为new $ git push origin new (如果new后面的冒号省略,表示远程分支也叫new) 查看,本地分支情况 ![](https://box.kancloud.cn/7d2049a142e26a0a8ababb5d26927c50_540x338.png) 第二种情况: 基于远程分支建立一个本地分支 * 在远程仓库上建立一个分支 ![](https://box.kancloud.cn/449406f8cdc266bd3490b6befb95d9f9_1553x491.png) * 把远程分支拉取到本地 $ git fetch From git.91als.net:root/yyg * [new branch] feature/test_dev -> origin/feature/test_dev * 基于远程分支建立一个本地关联分支 Administrator@WIN-0JU14CFTKDB MINGW32 ~/Desktop/yyg (new) $ git branch -a Develop gray-dev-m master * new remotes/origin/HEAD -> origin/master remotes/origin/feature/Develop remotes/origin/feature/test_dev remotes/origin/gray-dev-m remotes/origin/master remotes/origin/new Administrator@WIN-0JU14CFTKDB MINGW32 ~/Desktop/yyg (new) $ git checkout -b test_dev origin/feature/test_dev Switched to a new branch 'test_dev' Branch 'test_dev' set up to track remote branch 'feature/test_dev' from 'origin' . 说明: test_dev: 本地分支名 origin:远程仓库 feature_dev:远程分支 Administrator@WIN-0JU14CFTKDB MINGW32 ~/Desktop/yyg (test_dev) $ git branch -a Develop gray-dev-m master new * test_dev remotes/origin/HEAD -> origin/master remotes/origin/feature/Develop remotes/origin/feature/test_dev remotes/origin/gray-dev-m remotes/origin/master remotes/origin/new 总结: * 通过以上2种情况,把本地分支和远程分支建立关联后,就可以直接进行pull和push咯 * git push origin test_dev 会直接推送到远程feature/test_dev里 2、删除远程分支 $ git push origin :mybranch2(远程分支)