Finished translating.

This commit is contained in:
Yufei-Yan 2022-08-08 03:29:53 -05:00
parent 2df8ff0f4c
commit 63de06473d
2 changed files with 102 additions and 99 deletions

View File

@ -1,99 +0,0 @@
[#]: subject: "Delete the local reference to a remote branch in Git"
[#]: via: "https://opensource.com/article/22/8/delete-local-reference-remote-branch-git"
[#]: author: "Agil Antony https://opensource.com/users/agantony"
[#]: collector: "lkxed"
[#]: translator: "MCGA"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Delete the local reference to a remote branch in Git
======
Follow a few simple steps to keep your Git repository tidy.
![A diagram of a branching process][1]
Image by: Opensource.com
After you merge a GitLab or GitHub pull request, you usually delete the topic branch in the remote repository to maintain repository hygiene. However, this action deletes the topic branch only in the remote repository. Your local Git repository also benefits from routine cleanup.
To synchronize the information in your local repository with the remote repository, you can execute the `git prune` command to delete the local reference to a remote branch in your local repository.
Follow these three simple steps:
### 1. Checkout the central branch of your repository (such as main or master)
```
$ git checkout <central_branch_name>
```
### 2. List all the remote and local branches
```
$ git branch -a
```
Example output:
```
4.10.z
* master
  remotes/mydata/4.9-stage
  remotes/mydata/4.9.z
  remotes/mydata/test-branch
```
In this example, `test-branch` is the name of the topic branch that you deleted in the remote repository.
### 3. Delete the local reference to the remote branch
First, list all the branches that you can delete or prune on your local repository:
```
$ git remote prune origin --dry-run
```
Example output:
```
Pruning origin
URL: git@example.com:myorg/mydata-4.10.git
* [would prune] origin/test-branch
```
Next, prune the local reference to the remote branch:
```
$ git remote prune origin
```
Example output:
```
Pruning origin
URL: git@example.com:myorg/mydata-4.10.git
* [pruned] origin/test-branch
```
That's it!
### Maintaining your Git repository
Keeping your Git repository tidy may not seem urgent at first, but the more a repository grows, the more important it becomes to prune unnecessary data. Don't slow yourself down by forcing yourself to sift through data you no longer need.
Regularly deleting local references to remote branches is a good practice for maintaining a usable Git repository.
--------------------------------------------------------------------------------
via: https://opensource.com/article/22/8/delete-local-reference-remote-branch-git
作者:[Agil Antony][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/agantony
[b]: https://github.com/lkxed
[1]: https://opensource.com/sites/default/files/lead-images/freesoftwareway_law3.png

View File

@ -0,0 +1,102 @@
[#]: subject: "Delete the local reference to a remote branch in Git"
[#]: via: "https://opensource.com/article/22/8/delete-local-reference-remote-branch-git"
[#]: author: "Agil Antony https://opensource.com/users/agantony"
[#]: collector: "lkxed"
[#]: translator: "MCGA"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
删除 Git 上远程分支的本地引用
======
遵循几个简单的步骤来保持 Git 仓库的整洁
![A diagram of a branching process][1]
Image by: Opensource.com
图片来源Opensource.com
在合并一个 GibLab 或 GitHub 的 pull request 后,通常需要从远程仓库中删掉这个主题分支来保持仓库的整洁。然而,这只会删掉远程仓库的主题分支。本地 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: git@example.com:myorg/mydata-4.10.git
* [would prune] origin/test-branch
```
然后,删除远程分支的本地引用:
```
$ git remote prune origin
```
示例输出:
```
Pruning origin
URL: git@example.com:myorg/mydata-4.10.git
* [pruned] origin/test-branch
```
就是这样!
### 维护 Git 仓库
保持 Git 仓库的整洁,一开始似乎并不紧急,但是随着仓库规模的增长,删除不必要的数据就变得更为重要。不要因为需要从无用的数据中挣脱出来而降低你的节奏。
经常删除远程分支的本地引用,对于维护一个可用的 Git 仓库是一个非常好的习惯。
--------------------------------------------------------------------------------
via: https://opensource.com/article/22/8/delete-local-reference-remote-branch-git
作者:[Agil Antony][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/agantony
[b]: https://github.com/lkxed
[1]: https://opensource.com/sites/default/files/lead-images/freesoftwareway_law3.png