0

I created a local branch in git called test1234 and pushed it to origin through Eclipse. But I did something really wrong because I got an email, "superbobbay pushed new branch HEAD" when I was expecting "superbobbay pushed new branch test1234"

git branch -r shows origin/HEAD->origin/master

cat .git/HEAD just returns a commit string "8da516...."

Is there a way to revert this? I can't seem to fetch/rebase anymore.

Mebin Joe
  • 2,172
  • 4
  • 16
  • 22
bobbay
  • 483
  • 4
  • 9
  • This might help: https://stackoverflow.com/questions/35736116/making-a-git-push-from-a-detached-head – Mebin Joe Apr 11 '19 at 06:01
  • I don't think I have a detached HEAD though. When I do a git status I get "On branch master. Your branch and 'origin/master' have diverged." Oh man, this is baddd. – bobbay Apr 11 '19 at 06:06
  • Are you using github ? – Abhishek Ranjan Apr 11 '19 at 06:25
  • I'm on gitlab. Is there a way to back out this change? – bobbay Apr 11 '19 at 06:36
  • This is technically possible, because a branch is simply a reference whose name starts with `refs/heads/`. So `refs/heads/HEAD` is a valid branch name whose short name is `HEAD`. It is, however, far more likely that you simply pushed your existing commits to `origin/master`, so that `origin/master` has the same commits as your local branch named `test1234`. – torek Apr 11 '19 at 06:36
  • 1
    @bobbay You can use the gitlab ui to go and manually delete the branch there. Then re-clone the repo and you'll have no trace of that branch. – Abhishek Ranjan Apr 11 '19 at 06:40
  • Thank you Abhishek, I deleted the branch on gitlab UI and fetched/rebased, things are back to normal. I don't think I need to re-clone though. Seems ok. WHEW! Thank you! – bobbay Apr 11 '19 at 06:43
  • @bobbay I have added the solution as a answer, kindly accept it – Abhishek Ranjan Apr 11 '19 at 06:55

2 Answers2

2

Go to .git directory in your local working copy, go to the refs subdir and find a file called like your branch - HEAD - and delete it.

Mind that I' writing about refs subdir. Not logs not root .git.

quetzalcoatl
  • 32,194
  • 8
  • 68
  • 107
1

since you've already pushed to origin, you can goto gitlab GUI -> Repository settings & delete the branch from there.

Then you can simply re-clone the repo, or delete the branch from your local repo to remove its existence completely.

Kudos !

Abhishek Ranjan
  • 498
  • 3
  • 17