Kiwi Rupela
Kiwi Rupela

Reputation: 2348

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

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

Upvotes: 1

Views: 94

Answers (2)

symlink
symlink

Reputation: 12209

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

Upvotes: 1

Romain Valeri
Romain Valeri

Reputation: 21908

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

Upvotes: 1

Related Questions