6

删除 Git 远程分支的本地引用

 1 year ago
source link: https://www.51cto.com/article/716174.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

删除 Git 远程分支的本地引用-51CTO.COM

删除 Git 远程分支的本地引用
作者:Agil Antony 2022-08-11 15:45:13
要同步本地仓库和远程仓库的信息,可以执行 git prune 命令来删除本地仓库中远程分支的本地引用。
5237666200fba75edf9010606df42971e72b82.jpg

遵循几个简单的步骤来保持 Git 仓库的整洁

在合并一个 GibLab 的合并请求(MR)或 GitHub 的拉取请求(PR)后,你通常需要从远程仓库中删掉这个主题分支来保持仓库的整洁。然而,这只会删掉远程仓库的主题分支。本地 Git 仓库也会从例行清理中收益。

要同步本地仓库和远程仓库的信息,可以执行 ​​git prune​​ 命令来删除本地仓库中远程分支的本地引用。

按照以下三个简单的步骤:

1、检出仓库中的核心分支(比如 ​​main​​​ 或者 ​​master​​):

$ git checkout <central_branch_name>

2、列出所有远程和本地分支:

$ git branch -a

示例输出:

4.10.z
    * master
      remotes/mydata/4.9-stage
      remotes/mydata/4.9.z
      remotes/mydata/test-branch

在这个例子中,​​test-branch​​ 是从远程仓库中删除的主题分支的名字。

3、删除远程分支的本地引用:

首先,列出所有可以从本地仓库中删除的分支:

$ git remote prune origin --dry-run

示例输出:

Pruning origin
    URL: [email protected]:myorg/mydata-4.10.git
    * [would prune] origin/test-branch

然后,删除远程分支的本地引用:

$ git remote prune origin

示例输出:

Pruning origin
    URL: [email protected]:myorg/mydata-4.10.git
    * [pruned] origin/test-branch

就是这样!

维护 Git 仓库

保持 Git 仓库的整洁,一开始似乎并不紧急,但是随着仓库规模的增长,删除不必要的数据就变得更为重要。不要让从无用的数据筛选而拖慢你。

经常删除远程分支的本地引用,是维护一个可用的 Git 仓库是一个好方法。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK