I've created a remote branch whose name starts with a hashtag mark and I've quickly learnt it's a bad idea as #
is considered as a comment mark by git.
Therefore, I would like to delete that branch now but I can't find a proper way to do so… I've tried :
git push origin --delete <#branch_name>
git push origin --delete -- <#branch_name>
But git always returns this error message
fatal: --delete doesn't make sense without any refs.
So how can I walk around that issue ?
Escape the #
:
git push origin --delete \#branch_name
↑
You can delete
any branch
by this command
$ git push origin +:refs/heads/#branch_name
or
git push origin :<#branch_name>
For this example, I will show how to delete the remote and local branches. If you have any doubts... SAVE a backup of your data! Normally, local and remote branch names would be identical, but I am adding a prefix "local-" and "remote-" to help clarify what is being deleted and where. Note, you cannot delete the default branch. (If you wish to, you must select another default branch first).
Say your default branch name on the remote github website for a repository called "myrepo" is: "remote-main", and the remote branch you wish to delete is "remote-subbranch".
On your local machine "myrepo" repository these are tracked with "local-main", and you wish to delete "local-subbranch" from the local repository.
Do:
your.name@identifiers123abc MINGW64 /path/to/your/local/myrepo (local-main)
$
$ git branch -a
*local-main
local-subbranch
remotes/myrepo/remote-main
remotes/myrepo/remote-subbranch
$ git branch -d local-subbranch
Deleted branch local-subbranch
$ git push -d remote-main remote-subbranch
To https://github.com/yourGHname/myrepo.git
- [deleted] remote-subbranch
$ git branch -a
*local-main
remotes/myrepo/remote-main
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With