【问题标题】:Then I removed a branch locally why this branch still works on github [duplicate]然后我在本地删除了一个分支,为什么这个分支仍然在 github 上工作 [重复]
【发布时间】:2021-04-18 07:35:38
【问题描述】:

这是一个关于 Git 和 GitHub 的基本新手问题。我只是想确保我做对了。我的项目有一个本地 Git 和一个 GitHub 存储库。我有 Master 和 Develop 分支,我创建了一个新分支,然后我在本地删除了一个分支,为什么这个分支在 github 上仍然有一个活动分支。

CORP+son.ngoc.ng@son-ngoc-ng01 MINGW64 /d/Project/... (son.ngoc.ng)
$ git checkout son.ngoc.ng
Already on 'son.ngoc.ng'
Your branch is up to date with 'origin/son.ngoc.ng'.

CORP+son.ngoc.ng@son-ngoc-ng01 MINGW64 /d/Project/... (son.ngoc.ng)
$ git checkout master
Switched to branch 'master'
Your branch is behind 'origin/master' by 47 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)

CORP+son.ngoc.ng@son-ngoc-ng01 MINGW64 /d/Project/... (master)
$ git branch -D son.ngoc.ng
Deleted branch son.ngoc.ng (was 40b60e8a).

CORP+son.ngoc.ng@son-ngoc-ng01 MINGW64 /d/Project/... (master)
$ git checkout son.ngoc.ng1
Switched to branch 'son.ngoc.ng1'

Github 概览


Default branch
master          Updated 3 hours ago by son-ngoc-ng      Default

Your branches
son.ngoc.ng1    Updated 3 hours ago by son-ngoc-ng              #55  Merged
son.ngoc.ng     Updated 4 hours ago by son-ngoc-ng              #54  Merged

Active branches
son.ngoc.ng1    Updated 3 hours ago by son-ngoc-ng              #55  Merged
son.ngoc.ng     Updated 4 hours ago by son-ngoc-ng              #54  Merged

【问题讨论】:

  • 我无法发布图片以获得更好的描述
  • 阅读此内容。希望你能得到你需要的东西:) Link

标签: git branch


【解决方案1】:

如果您删除本地存储库中的分支,这并不意味着它将自动从 GIT 中删除。要从 git 中删除 if,请转到以下文档:

https://docs.github.com/en/free-pro-team@latest/github/collaborating-with-issues-and-pull-requests/creating-and-deleting-branches-within-your-repository

【讨论】:

    【解决方案2】:

    因为您可能已经将新创建的分支推送到远程 github。所以你必须删除远程和本地分支。如果您还没有将您的分支推送到远程 github,则可以删除本地分支。

    【讨论】:

      【解决方案3】:

      请参考以下步骤删除远程和本地分支:

      在 git 中删除本地分支

      $ git branch -d feature/login
      

      在 git 中删除远程分支

      $ git push origin --delete feature/login
      

      【讨论】:

      • 不删除github repo
      猜你喜欢
      • 1970-01-01
      • 2023-01-17
      • 2020-11-19
      • 1970-01-01
      • 2017-03-07
      • 2016-01-15
      • 2015-12-22
      • 1970-01-01
      • 2021-12-11
      相关资源
      最近更新 更多