一、创建新分支:
- 新建分支:
macbook:portal zhaoxueyong$ git checkout -b branch-test
M project/settings.py
Switched to a new branch 'branch-test'
macbook:portal zhaoxueyong$ git status
On branch branch-test
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: project/settings.py
no changes added to commit (use "git add" and/or "git commit -a")
macbook:portal zhaoxueyong$ git push origin branch-test
Total 0 (delta 0), reused 0 (delta 0)
To http://code.cbpmgt.com/VPC/portal.git
* [new branch] branch-test -> branch-test
macbook:portal zhaoxueyong$ git branch -a
* branch-test
master
release-2.0
remotes/origin/HEAD -> origin/master
remotes/origin/branch-test
remotes/origin/master
remotes/origin/release-1.0
remotes/origin/release-2.0
-
查看gitlab上分支情况:
二、页面上删除分支:
点击上图分支后的删除按钮删除对应分支;
三、本地查看分支:
macbook:portal zhaoxueyong$ git branch -a
* branch-test
master
release-2.0
remotes/origin/HEAD -> origin/master
remotes/origin/branch-test
remotes/origin/master
remotes/origin/release-1.0
remotes/origin/release-2.0
四、本地同步分支:
macbook:portal zhaoxueyong$ git fetch origin
macbook:portal zhaoxueyong$ git branch -a
* branch-test
master
release-2.0
remotes/origin/HEAD -> origin/master
remotes/origin/branch-test
remotes/origin/master
remotes/origin/release-1.0
remotes/origin/release-2.0
由上述操作知,git fetch
不能在本地同步删除远端已经删除的分支;
macbook:portal zhaoxueyong$ git remote prune origin
Pruning origin
URL: http://jrzhaoxueyong:xyz198920@code.cbpmgt.com/VPC/portal.git
* [pruned] origin/branch-test
macbook:portal zhaoxueyong$ git branch -a
* branch-test
master
release-2.0
remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/origin/release-1.0
remotes/origin/release-2.0
可以看到remotes中已经没有branch-test的分支了;
此时把本地的branch-test分支删除即可;
macbook:portal zhaoxueyong$ git checkout master
M project/settings.py
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
macbook:portal zhaoxueyong$ git branch -d branch-test
Deleted branch branch-test (was 5bfd8184).
macbook:portal zhaoxueyong$ git branch
* master
release-2.0