玩转GIT系列之【git的分支操作(查看分支/切换分支/新建分支/删除分支)】
生活随笔
收集整理的這篇文章主要介紹了
玩转GIT系列之【git的分支操作(查看分支/切换分支/新建分支/删除分支)】
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、查看分支
1、查看全部分支
git branch -a2、查看本地分支
git branch -l3、查看遠程分支
git branch -r二、切換分支
假設本地當前處于master分支下,遠端有一個test1分支和一個test2分支,想要切換到test1這個分支,怎么辦?
git branch -a * masterremotes/origin/HEAD -> origin/masterremotes/origin/test1remotes/origin/test2remotes/origin/master可以使用以下兩個命令中的任何一個:
git checkout test1 git checkout -b test1 remotes/origin/test1請注意:checkout命令如果使用了-b的語法,則一定要攜帶一個遠端分支作為參數,否則,該命令的執行效果就變成了:在本地新建一個分支,基于master分支,但是與遠端的test1分支并無任何關系。
以下是上述各個命令的執行效果:
git checkout test1 Branch test1 set up to track remote branch test1 from origin. Switched to a new branch 'test1'git checkout -b test1 remotes/origin/test1 Branch test1 set up to track remote branch test1 from origin. Switched to a new branch 'test1'git checkout -b test1 Switched to a new branch 'test1'請自行仔細對比上述3個命令之間的差異!!!
三、新建分支
1、創建分支
git branch name2、切換分支
git checkout name3、創建+切換分支
git checkout -b name四、刪除分支
1、刪除本地分支
git branch -d branch_name git branch -D branch_name2、刪除遠程分支
git push origin :branch_name請注意:origin后面有一個空格
五、重命名分支
git branch (-m | -M) <oldbranch> <newbranch>重命名oldbranch為newbranch,使用-M則表示強制重命名。
如果你需要重命名遠程分支,推薦的做法是:
1、刪除遠程待修改分支;
2、push本地新分支名到遠程;
六、待添加
總結
以上是生活随笔為你收集整理的玩转GIT系列之【git的分支操作(查看分支/切换分支/新建分支/删除分支)】的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 还有这种操作2第78关怎么过
- 下一篇: C语言中open与fopen的的解释和区