Git实战指南----跟着haibiscuit学Git(第六篇)

笔名:  haibiscuit

博客园: https://www.cnblogs.com/haibiscuit/

Git地址: https://github.com/haibiscuit?tab=repositories  (欢迎star)

本项目地址: https://github.com/haibiscuit/StudyBook

尊重笔者的劳动成果,未经允许请不要转载

:分支操作

创建分支

(1) 场景一 本地和远程分支都存在(关联分支)

git branch --set-upstream-to=origin/dev dev

(2) 场景二 本地分支dev存在,但远程分支不存在

git push --set-upstream origin dev   //远程创建dev分支并与本地建立关联

(3) 场景三 远程分支存在,需要新建对应的本地分支

git checkout --track origin/dev

其他分支操作

(1) 查看本地仓库和远程仓库的关系

git branch -vv

(2) 列出本地和远程分支

git branch -a

(3) 查看远程分支

    git branch -v

(4) 创建并切换到本地分支

git checkout -b <branch-name>

(5) 从远程分支中创建并切换到本地分支

git checkout -b <branch-name> origin/<branch-name>

(6) 删除本地分支

git branch -d <local-branchname>

(7) 删除远程分支

git push origin --delete <remote-branchname>

或者

git push origin :<remote-branchname>

(8) 重命名本地分支

git branch -m <new-branch-name>

猜你喜欢

转载自www.cnblogs.com/haibiscuit/p/11986407.html