Git- some how a single branch having two names created how do i make it single

烂漫一生 提交于 2020-05-16 22:01:35

问题


I just tried to rename the branch with following command

git branch -m <oldname> <newname> 

my older branch name is feature/AAM-443 and this branch is already merged with parent now when i renamed it with feature/AAMN-443 and push it to remote then the branch in network is showing

*<commit id> feature/AAM-443, feature/AAMN-443 

and if i do some commit to feature/AAMN-443 then graph is like

 * <new-commit id> feature/AAMN-443
 |
 |
 * <old-commit id> feature/AAM-443

what is happening i am wondering that what the meaning of a branch having two names is it some symbolic reference and why the feature/AAM-443 is still there why not it removed can anyone help


回答1:


To add to @RomainValeri's answer, a branch can't have two names, so what you did was this:

You had a remote tracking branch:

git branch -a

feature/AAM-443
origin/feature/AAM-443 <-- tracked by feature/AAM-443

You renamed your branch locally:

git branch -m feature/AAM-443 feature/AAMN-443

git branch -a

feature/AAMN-443 
origin/feature/AAM-443 <-- still thinks it's tracked by feature/AAM-443

You pushed your renamed branch to origin:

git push -u feature/AAMN-443
git branch -a

feature/AAMN-443
origin/feature/AAMN-443 <-- tracked by feature/AAMN-443
origin/feature/AAM-443 <-- no longer tracked by any local branch!

Then you made a new commit and pushed:

git commit -am "new commit" <-- on branch feature/AAMN-443

Your remote repo updated like this:

o <-- origin/feature/AAMN-443
|
o <-- origin/feature/AAM-443 (branch is no longer tracked! It has been left behind!!)

Like @RomainValeri said, you need to delete origin/feature/AAM-443:

git push --delete origin feature/AAM-443



回答2:


You just have to remove the remote counterpart that's still there.

(assuming your remote is named origin here)

git push --delete origin feature/AAM-443

# or

git push origin :feature/AAM-443


来源:https://stackoverflow.com/questions/61367248/git-some-how-a-single-branch-having-two-names-created-how-do-i-make-it-single

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!