git branch 相关操作总结 新建分支 删除分支 切换分支 查看分支
2017-03-29 18:10
666 查看
查看分支
(1) 查看本地分支 git branch 列出本地已经存在的分支,并且在当前分支的前面加*号标记,例如:
localhost:website admin$ git branch
* branch_dev_2_1_0
master
(2) 查看远程分支 git branch -r 例如:
localhost:website admin$ git branch -r
origin/branch_dev_2_1_0
origin/branch_dev_2_1_0_cover
origin/branch_dev_2_1_0_metrics
origin/branch_dev_2_1_0_php7
origin/master
(3) 查看所有分支 git branch -a 例如:
localhost:website admin$ git branch -a
* branch_dev_2_1_0
master
origin/branch_dev_2_1_0
origin/branch_dev_2_1_0_cover
origin/branch_dev_2_1_0_metrics
origin/branch_dev_2_1_0_php7
origin/master
新建分支
(1)新建分支但不切换到该分支 git branch 分支名,例如:
localhost:website admin$ git branch
* branch_dev_2_1_0
master
localhost:website admin$ git branch new_branch
localhost:website admin$ git branch
* branch_dev_2_1_0
master
new_branch
可以看出,虽然新建了本地分支 new_branch 但是当前分支并没有切换(带*号为当前分支)
(2) 新建并切换到该分支 git checkout -b 分支名,例如:
localhost:website admin$ git branch
* branch_dev_2_1_0
master
localhost:website admin$ git checkout -b new_branch
Switched to a new branch 'new_branch'
localhost:website admin$ git branch
branch_dev_2_1_0
master
* new_branch
新建本地分支 new_branch 的同时将当前分支切换为 new_branch (带*号为当前分支)
分支切换
git checkout 分支名,例如:
localhost:website admin$ git branch
branch_dev_2_1_0
master
* new_branch
localhost:website admin$ git checkout master
Switched to branch 'master'
localhost:website admin$ git branch
branch_dev_2_1_0
* master
new_branch
可以看出,原来的分支为 new_branch ,执行完 git checkout master 后,将分支切换到 master(带*号为当前分支)
删除本地分支
git branch -d 分支名,例如:
localhost:website admin$ git branch
* branch_dev_2_1_0
master
new_branch
localhost:website admin$ git branch -d new_branch
Deleted branch new_branch (was e6d6ae0).
localhost:website admin$ git branch
* branch_dev_2_1_0
master
可以看出,原来总共有3个分支,删除 new_branch后变成了两个分支
(1) 查看本地分支 git branch 列出本地已经存在的分支,并且在当前分支的前面加*号标记,例如:
localhost:website admin$ git branch
* branch_dev_2_1_0
master
(2) 查看远程分支 git branch -r 例如:
localhost:website admin$ git branch -r
origin/branch_dev_2_1_0
origin/branch_dev_2_1_0_cover
origin/branch_dev_2_1_0_metrics
origin/branch_dev_2_1_0_php7
origin/master
(3) 查看所有分支 git branch -a 例如:
localhost:website admin$ git branch -a
* branch_dev_2_1_0
master
origin/branch_dev_2_1_0
origin/branch_dev_2_1_0_cover
origin/branch_dev_2_1_0_metrics
origin/branch_dev_2_1_0_php7
origin/master
新建分支
(1)新建分支但不切换到该分支 git branch 分支名,例如:
localhost:website admin$ git branch
* branch_dev_2_1_0
master
localhost:website admin$ git branch new_branch
localhost:website admin$ git branch
* branch_dev_2_1_0
master
new_branch
可以看出,虽然新建了本地分支 new_branch 但是当前分支并没有切换(带*号为当前分支)
(2) 新建并切换到该分支 git checkout -b 分支名,例如:
localhost:website admin$ git branch
* branch_dev_2_1_0
master
localhost:website admin$ git checkout -b new_branch
Switched to a new branch 'new_branch'
localhost:website admin$ git branch
branch_dev_2_1_0
master
* new_branch
新建本地分支 new_branch 的同时将当前分支切换为 new_branch (带*号为当前分支)
分支切换
git checkout 分支名,例如:
localhost:website admin$ git branch
branch_dev_2_1_0
master
* new_branch
localhost:website admin$ git checkout master
Switched to branch 'master'
localhost:website admin$ git branch
branch_dev_2_1_0
* master
new_branch
可以看出,原来的分支为 new_branch ,执行完 git checkout master 后,将分支切换到 master(带*号为当前分支)
删除本地分支
git branch -d 分支名,例如:
localhost:website admin$ git branch
* branch_dev_2_1_0
master
new_branch
localhost:website admin$ git branch -d new_branch
Deleted branch new_branch (was e6d6ae0).
localhost:website admin$ git branch
* branch_dev_2_1_0
master
可以看出,原来总共有3个分支,删除 new_branch后变成了两个分支
相关文章推荐
- 【git系列之E】git的分支操作(查看分支、切换分支、新建分支和删除分支)
- git branch用法总结,查看、新建、删除、重命名
- Git使用手册/Git教程:git branch 分支操作、创建分支、查看分支、删除分支、删除本地分支、删除远程分支
- git分支的创建、切换、合并及删除操作小结
- git分支(branch)操作相关命令及分支命令的使用
- git 撤销分支删除 操作 (git delete branch undo)
- git命令查看、创建、切换、删除分支
- git分支(branch)操作相关命令
- Git命令查看、创建、切换、删除分支
- git分支(branch)操作相关命令
- git查看/新建/删除远程分支
- git创建新分支,查看分支,删除分支,切换分支等问题
- git---基本操作、新建分支,合并分支branch到主干master ,git pull ,git push
- git 查看、创建、切换、合并、删除分支
- git 撤销分支删除 操作 (git delete branch undo)
- git 下 分支创建 合并 删除 相关操作
- Git分支 -新建,切换,删除,合并
- GIT查看、删除、重命名远程分支和TAG
- git 查看远程分支、本地分支、创建分支、推送分支到远程repository、获取远程分支、删除本地、远程分支
- git 查看远程分支、本地分支、删除本地分支