Git分支建立和刪除
建立本地分支
#檢視本地和遠端分支,此時還沒有temp分支
cc@cc-PC MINGW64 /f/my-center/cloud/server-services-config (master)
$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
#新建本地分支temp
cc@cc-PC MINGW64 /f/my-center/cloud/server-services-config (master)
$ git branch temp
#檢視,發現有 temp說明已經有本地分支
cc@cc-PC MINGW64 /f/my-center/cloud/server-services-config (master)
$ git branch -a
* master
temp
remotes/origin/HEAD -> origin/master
remotes/origin/master
#切換到本地temp分支
cc@cc-PC MINGW64 /f/my-center/cloud/server-services-config (master)
$ git checkout temp
Switched to branch 'temp'
M consumer-task/pom.xml
#檢視,發現* temp說明已經切換到本地temp分支
cc@cc-PC MINGW64 /f/my-center/cloud/server-services-config (temp)
$ git branch -a
master
* temp
remotes/origin/HEAD -> origin/master
remotes/origin/master
此外若已經有遠端分支,也可以利用遠端分支來建立本地分支:
- git checkout -b my_develop origin/develop
- git fetch origin my_develop:develop
git checkout my_develop
建立遠端分支
#編輯檔案
cc@cc-PC MINGW64 /f/my-center/cloud/server-services-config (temp)
$ vim README
#add檔案
cc@cc-PC MINGW64 /f/my-center/cloud/server-services-config (temp)
$ git add README
warning: LF will be replaced by CRLF in README.
The file will have its original line endings in your working directory.
#commit檔案
cc@cc-PC MINGW64 /f/my-center/cloud/server-services-config (temp)
$ git commit -m "add README"
[temp 95447d5] add README
1 file changed, 1 insertion(+)
create mode 100644 README
#push改動並把本地temp分支push到遠端temp;若遠端沒有temp,則建立遠端temp分支,並完成本地temp對遠端temp的跟蹤
cc@cc-PC MINGW64 /f/my-center/cloud/server-services-config (temp)
$ git push origin temp:temp
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 293 bytes | 146.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote:
remote: To create a merge request for temp, visit:
remote: http://gitlab.ushareit.org:8000/interlive/cloud/server-services-config/merge_requests/new?merge_request%5Bsource_branch%5D=temp
remote:
To gitlab.ushareit.org:interlive/cloud/server-services-config.git
* [new branch] temp -> temp
#檢視本地和遠端分支,發現有了remotes/origin/temp遠端分支
cc@cc-PC MINGW64 /f/my-center/cloud/server-services-config (temp)
$ git branch -a
master
* temp
remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/origin/temp
刪除遠端分支
#刪除遠端分支temp
cc@cc-PC MINGW64 /f/my-center/cloud/server-services-config (temp)
$ git push origin --delete temp
To gitlab.ushareit.org:interlive/cloud/server-services-config.git
- [deleted] temp
#檢視發現已經沒有遠端分支temp
cc@cc-PC MINGW64 /f/my-center/cloud/server-services-config (temp)
$ git branch -a
master
* temp
remotes/origin/HEAD -> origin/master
remotes/origin/master
#總結有如下兩種方式,第二種方式也較為常用
1)使用命令 git push origin --delete temp(temp為遠端分支名稱)
2)使用命令 git push origin :temp
刪除本地分支
#檢視,發現有本地分支temp
cc@cc-PC MINGW64 /f/my-center/cloud/server-services-config (temp)
$ git branch -a
master
* temp
remotes/origin/HEAD -> origin/master
remotes/origin/master
#需要先切換到目標之外的分支,才能刪除目標分支
cc@cc-PC MINGW64 /f/my-center/cloud/server-services-config (temp)
$ git checkout master
Switched to branch 'master'
M weshow-sqs-consumer-task/pom.xml
Your branch is up to date with 'origin/master'.
#如還有未被提交的change,執行如下命令會有錯誤提示
cc@cc-PC MINGW64 /f/my-center/cloud/server-services-config (master)
$ git branch -d temp
error: The branch 'temp' is not fully merged.
If you are sure you want to delete it, run 'git branch -D temp'.
#需要用如下命令進行刪除
cc@cc-PC MINGW64 /f/my-center/cloud/server-services-config (master)
$ git branch -D temp
Deleted branch temp (was 95447d5).
相關文章
- git分支建立刪除,打tagGit
- git刪除本地分支命令 git怎麼刪除本地分支Git
- Git刪除指定分支Git
- git刪除本地分支Git
- Git 操作——如何刪除本地分支和遠端分支Git
- git 批量刪除本地分支Git
- git 刪除遠端分支Git
- Gerrit上分支操作記錄(建立分支、刪除分支)
- 恢復 Git 被刪除的分支Git
- Git恢復被刪除的分支Git
- git刪除本地分支出現錯誤Git
- Git批量刪除分支| 8月更文挑戰Git
- Gitlab刪除分支Gitlab
- git建立與切換分支Git
- 建立元素和刪除元素
- JavaScript 建立和刪除元素JavaScript
- Git檢視分支建立時間Git
- git 從master建立新的分支GitAST
- oracle job的建立和刪除Oracle
- git分支管理和stashGit
- Git 推送和刪除遠端標籤Git
- ubuntu 建立和刪除使用者Ubuntu
- mysql 建立和刪除聯合索引MySql索引
- Git——刪除檔案Git
- Git(12)-- Git 分支 - 分支簡介Git
- Git基於指定stash儲藏建立分支Git
- Git基於指定commit提交建立分支GitMIT
- Git分支和版本回退Git
- Oracle使用者的建立和刪除Oracle
- 【筆記】Git 中的分支建立和衝突解決(命令列)筆記Git命令列
- Git 分支的建立與切換 —— Git 學習筆記 14Git筆記
- mongodb建立索引和刪除索引和背景索引backgroundMongoDB索引
- Git刪除指定檔案Git
- Git刪除tag標籤Git
- Git刪除指定commitGitMIT
- git 刪除本地倉庫Git
- git刪除資料夾Git
- git分支Git