创建分支: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权威指南》