自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

如何刪除遠(yuǎn)程 git 分支

系統(tǒng) Linux
我們今天介紹一下刪除遠(yuǎn)程 git 分支的步驟。一起來看一下吧。

刪除 git 本地分支比較容易,可直接使用命令:

git branch -d

但是要刪除一個遠(yuǎn)程的 git 分支,就不一樣了,我們今天介紹一下刪除遠(yuǎn)程 git 分支的步驟。

查看遠(yuǎn)程分支列表

要查看遠(yuǎn)程 git 倉庫中的所有分支,可使用 -a 選項,如下所示:

$ git branch -a
? master
dev
remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/origin/dev

上述是在 clone 的一個 dust 倉庫中運(yùn)行 git branch -a 的輸出結(jié)果。我們把這個結(jié)果分解來看:

  • remotes:指遠(yuǎn)程服務(wù)器上的存儲庫(如 GitLab、Gitea 或 GitHub);
  • origin:系統(tǒng)中遠(yuǎn)程倉庫的別名;
  • HEAD:默認(rèn)分支,如果沒有指定分支,則 clone 該分支。

如上所述,上述代碼中第 4 行, remotes/origin/HEAD -> origin/master,表示遠(yuǎn)程倉庫默認(rèn)的分支是 master 分支。

最后兩行表示在遠(yuǎn)程倉庫中有兩個分支,即 master 和 dev。

另外一種查看遠(yuǎn)程倉庫信息的方法是使用 git remote 命令,如下所示:

    $ git remote show origin
    ? remote origin
    Fetch URL:??git@github.com??:liugl/proj.git
    Push URL:??git@github.com??:liugl/proj.git
    HEAD branch: master
    Remote branches:
    master tracked
    dev tracked
    Local branches configured for 'git pull':
    master merges with remote master
    dev merges with remote dev
    Local refs configured for 'git push':
    master pushes to master (up to date)
    dev pushes to dev (up to date)

    git remote 命令的輸出信息更加詳細(xì)。這兩個查看分支的命令,大家可以根據(jù)各自喜好和習(xí)慣來選擇使用。

    刪除遠(yuǎn)程 git 分支

    在 git branch 命令后使用 -d(或者 -D 表示強(qiáng)制刪除)選項可用于刪除本地分支。

    但是要刪除遠(yuǎn)程倉庫中的分支,使用 git branch 命令是不起作用的。要刪除遠(yuǎn)程 git 分支,還需要使用 git push 命令,如下語法所示:

    $ git push origin --delete dev
    To ??github.com??:liugl/proj.git
    ? [deleted] dev
    $ git branch -a
    ? master
    dev
    remotes/origin/HEAD -> origin/master
    remotes/origin/master

    如上刪除中,使用 git push 命令刪除遠(yuǎn)程 git 分支后,并沒有刪除本地分支。

    刪除HEAD分支

    HEAD 分支是默認(rèn)分支的別名,在大多數(shù)存儲庫中,默認(rèn)分支為 master 或者 main。

    接下來我們嘗試一下刪除遠(yuǎn)程默認(rèn)分支...

    $ git branch -a
    ? master
    dev
    remotes/origin/HEAD -> origin/master
    remotes/origin/master
    remotes/origin/dev
    $ git push origin --delete master
    To ??github.com??:liugl/proj.git
    ! [remote rejected] master (refusing to delete the current branch: refs/heads/master)
    error: failed to push some refs to '??github.com??:liugl/proj.git'

    如上所示,當(dāng)我們嘗試刪除主分支的時候,拋出了一個錯誤,刪除失敗。也就是說,(一般情況下)主分支無法刪除。

    責(zé)任編輯:龐桂玉 來源: TIAP
    相關(guān)推薦

    2022-08-11 15:45:13

    Git

    2022-05-25 16:51:41

    Git 分支重命名開發(fā)者

    2020-07-09 08:00:25

    Git分支模式

    2021-03-28 17:21:15

    Git分支策略

    2018-06-08 09:27:08

    GitLinux開源

    2014-08-08 10:20:23

    Git版本管理系統(tǒng)

    2020-09-06 09:55:13

    git分支命令

    2022-10-26 09:28:17

    git分支Linux

    2023-12-01 11:05:29

    Git 分支

    2023-10-09 08:39:33

    Git Flow分支管理模型

    2022-11-07 08:01:18

    Git分支管理

    2024-04-03 09:03:05

    項目分支管理

    2020-05-28 10:45:31

    Git分支合并

    2011-03-30 10:50:55

    GitLinux 版本控制

    2022-03-18 09:45:43

    Git分支Linux

    2013-10-09 10:04:20

    LinuxGit

    2020-12-11 22:16:34

    Git遠(yuǎn)程倉庫Linux

    2024-10-28 00:00:25

    GitCIfeature

    2022-02-14 06:35:26

    git參數(shù)Jenkins開發(fā)

    2024-04-18 09:12:58

    Git分支代碼
    點(diǎn)贊
    收藏

    51CTO技術(shù)棧公眾號