古詩詞大全網 - 四字成語 - git branch用法總結,查看、新建、刪除、重命名

git branch用法總結,查看、新建、刪除、重命名

1.git branch查看本地所有分支

2.git branch -r查看遠程所有分支

3.git branch -a查看本地和遠程所有分支

如圖,壹般當前本地分支前帶有“*”號且為綠色,遠程分支為紅色

新建壹個分支,但不切換。如圖新建了test分支,但是目前依舊在dev5.7分支上。

妳可以使用 git checkout -b <branchname> 新建並切換至新分支

1.git branch -d <branchname>刪除本地分支,其中<branchname>為本地分支名

2.git branch -d -r <branchname>刪除遠程分支,其中<branchname>為本地分支名

刪除後,還要推送到服務器上才行,即git push origin :<branchname>

如圖刪除本地test分支,使用-D則表示強制刪除,相當於 --delete --force

如圖重命名oldbranch為newbranch,使用-M則表示強制重命名。

如果妳需要重命名遠程分支,推薦的做法是:

-d --delete:刪除

-D --delete --force的快捷鍵

-f --force:強制

-m --move:移動或重命名

-M --move --force的快捷鍵

-r --remote:遠程

-a --all:所有