1

I mistakenly named a branch and pushed it to Github, even opened the pull request.

Now I want to rename the branch like this, But if I do, it will delete the old branch and create a new one with the correct name. The issue is, that I don't want the owner of the repo to see that I have deleted a branch. I completely want the branch with the wrong name gone from git history.

Is there any other way I can achieve this? I don't want to lose the code too. Please help me with this, I have searched a lot but couldn't find a related solution to my problem. Thanks

torek
  • 448,244
  • 59
  • 642
  • 775
Adnan Sheikh
  • 760
  • 3
  • 13
  • 27
  • renames are _local_ operations. You can then push the new branch. if you didn't rebase or whatever, git will just create the new branch in the remote, the old branch will be kept as it was.... that won't change the PR, just in case. – eftshift0 Sep 05 '22 at 07:04
  • @eftshift0 actually my concern is different, I want to delete the old branch completely from git history, it should not even appear as deleted. – Adnan Sheikh Sep 05 '22 at 07:06
  • Don't know what you want _specifically_. You could: push the renamed branch so it is in the remote (github?), then change the PR to use the new branch. Then delete the old branch (`git push origin :old-branch). That might be what you want? – eftshift0 Sep 05 '22 at 07:11
  • @eftshift0 yes I have done the exact same, But if I go to pull requests, it shows the previous PR as deleted. I don't want this to appear there. The owner of the repo can still see that deleted branch with the wrong name. – Adnan Sheikh Sep 05 '22 at 07:15
  • The owner of the repo *should* see all operations, by design. The problem here is not technical, but organisational, if I may. – Romain Valeri Sep 05 '22 at 07:20
  • @RomainValeri you are right, But that name of the branch is very stupid and he might fire me immediately on this. A junior developer did this but I am leading the project. – Adnan Sheikh Sep 05 '22 at 07:25
  • @AdnanSheikh On a personal level, I can totally relate. These things happen. I don't know of a solution but I hope someone will have a useful suggestion. – Romain Valeri Sep 05 '22 at 07:27

1 Answers1

3

Git branch names are ephemeral. You can delete the branch name and it's gone. (The commits themselves are a different question as they are independent of the branch name.)

GitHub Pull Requests are permanent. They are not in Git, they are in GitHub. They are stored in a database that you cannot change. The only thing you can do here is contact GitHub support.

torek
  • 448,244
  • 59
  • 642
  • 775