git config_error ai_generated true

fatal: A branch named 'feature/new-ui' already exists.

ID: git/rename-branch-conflict

Also available as: JSON · Markdown · 中文
80%Fix Rate
83%Confidence
1Evidence
2023-11-20First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
git 2.42.0 active
git 2.43.0 active
git 2.44.0 active

Root Cause

Attempting to create or rename a branch to a name that already exists in the repository.

generic

中文

尝试创建或重命名分支到已存在的分支名称

Official Documentation

https://git-scm.com/docs/git-branch

Workarounds

  1. 85% success Delete the existing branch first if safe: git branch -D feature/new-ui && git branch -m old-name feature/new-ui
    Delete the existing branch first if safe: git branch -D feature/new-ui && git branch -m old-name feature/new-ui
  2. 75% success Force push the renamed branch after local rename: git push origin --delete feature/new-ui && git push origin feature/new-ui
    Force push the renamed branch after local rename: git push origin --delete feature/new-ui && git push origin feature/new-ui

中文步骤

  1. Delete the existing branch first if safe: git branch -D feature/new-ui && git branch -m old-name feature/new-ui
  2. Force push the renamed branch after local rename: git push origin --delete feature/new-ui && git push origin feature/new-ui

Dead Ends

Common approaches that don't work:

  1. Using 'git branch -m old new' when 'new' already exists on remote 80% fail

    Local rename does not check remote; push will fail with non-fast-forward

  2. Deleting the local branch with 'git branch -D new' then trying to rename 70% fail

    Remote branch still exists; push will still fail