創建分支:git branch branchname
~~~
$ git branch new_branch
Administrator@MY-PC /D/worksp/sample (master)
~~~
顯示本地分支列表:git branch
~~~
$ git branch
* master
new_branch
~~~
切換分支:git checkout branchname
~~~
$ git checkout new_branch
M src/string.py
Switched to branch 'new_branch'
~~~
創建和切換分支的快捷方式:
在上面的例子中,分別使用兩個命令創建和切換分支。 Git為checkout命令提供-b選項; 此操作將創建一個新的分支,并立即切換到新分支。
~~~
$ git checkout -b test_branch
M src/string.py
Switched to a new branch 'test_branch'
Administrator@MY-PC /D/worksp/sample (test_branch)
~~~
顯示本地分支列表:git branch
~~~
$ git branch
master
new_branch
* test_branch
~~~
刪除分支
可以通過向git branch命令提供-D選項來刪除分支。 但在刪除現有分支之前,請切換到其他分支。
如上面所示,目前在test_branch分支,如要想刪除該分支。需要先切換到其它分支再刪除此分支,如下所示。
~~~
$ git branch
master
new_branch
* test_branch
Administrator@MY-PC /D/worksp/sample (test_branch)
~~~
先切換到其它分支:
~~~
$ git checkout master
M src/string.py
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 4 commits.
(use "git push" to publish your local commits)
Administrator@MY-PC /D/worksp/sample (master)
~~~
刪除分支
~~~
$ git branch -D test_branch
Deleted branch test_branch (was b759faf).
Administrator@MY-PC /D/worksp/sample (master)
~~~
當前剩下的分支如下 -
~~~
$ git branch
* master
new_branch
~~~
當前剩下的分支如下 -
~~~
$ git branch
* master
new_branch
~~~
重命名分支
假設需要在項目中添加對寬字符的支持。并且已經創建了一個新的分支,但分支名稱需要重新命名。那么可通過使用-m選項后跟舊的分支名稱和新的分支名稱來更改/重新命名分支名稱。
~~~
$ git branch
* master
new_branch
Administrator@MY-PC /D/worksp/sample (master)
~~~
重命名分支
~~~
$ git branch -m new_branch wchar_support
~~~
現在,使用git branch命令顯示新的分支名稱。
~~~
$ git branch
* master
wchar_support
~~~
將遠程共享服務器的改動獲取到本地并和本地提交合并:git pull
* * * * *
https://www.yiibai.com/git/git_managing_branches.html
- 目錄
- 撤銷
- Git reset
- Git revert
- Git reset 命令
- Git的撤消操作 - 重置, 簽出和撤消
- 沖突
- 解決Git合并分支發生的沖突
- BASH
- 復制黏貼
- 教程
- 合并
- 合并提交
- 分支
- Gitee(碼云)
- Github
- 免費私有庫
- 本地倉庫推送到github倉庫
- 工具
- SourceTree
- 添加git-bash.exe到環境變量
- Git
- 安裝
- 配置
- 命令行
- 10個技巧讓開發者的Git水平迅速提升
- 3.2 Git 分支 - 分支的新建與合并
- 遠程分支
- Git幫助
- Git幫助
- 顯示命令幫助
- Git 命令
- 參數配置
- 還原至上次提交
- Git 操作命令
- Git tag
- Git 分支管理
- 認識分支
- 賣主分支
- 分支操作
- 本地倉庫遠程提交
- Git 分區
- 認識里程碑
- 忽略文件
- 已有項目
- 《Git權威指南》