1

I was working on some proof-of-concept code and had created a branch for it. Since it took close to 2 weeks, i was also pushing it to the remote on a daily basis.

The POC is now done and I do not want to merge it. I was able to delete the local branch with git branch -D <branchname>

But when i try to push it fails with the merge error (Branches cannot be deleted until merged). Is there a way to delete unmerged branches remotely?

Viking22
  • 545
  • 1
  • 7
  • 19
  • What hosting platform are you using on the remote side? GitHub, GitLab, Bitbucket, something else? – bk2204 May 02 '20 at 01:42
  • It is Stash/Bitbucket – Viking22 May 02 '20 at 01:48
  • 1
    Does this answer your question? [How do I delete a Git branch locally and remotely?](https://stackoverflow.com/questions/2003505/how-do-i-delete-a-git-branch-locally-and-remotely) – Inigo May 02 '20 at 10:32
  • @inigo not really. I think what CodeWizard has mentioned looks like the likely issue here. I am checking with my Git admins if they have the restriction set up. – Viking22 May 03 '20 at 03:01

2 Answers2

3

Is there a way to delete unmerged branches remotely?

git push :origin/branch

# or
git push origin --delete branch

According to your comments, you cant do it on bitbucket, the reason can be since your administrator blocked the option to delete branches

Prevert Deletion in the following screenshot

enter image description here

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • This gives the error that Branches that have not been merged cannot be deleted – Viking22 May 02 '20 at 01:48
  • 1
    This is the way to do it, so if it doesn't work, then the answer is “no,” and you'll have to figure out why Bitbucket is not letting you delete the branch. Contact your server administrator. – bk2204 May 02 '20 at 01:59
  • 1
    If you cant your administrator blocked it with restrictions – CodeWizard May 02 '20 at 04:35
2

In Git, local and remote branches are separate objects. Deleting a local branch doesn’t remove the remote branch.

To delete a remote branch, use the git push command with the -d (--delete) option:

git push remote_name --delete branch_name

Where remote_name is usually origin:

Output:
...
 - [deleted]         branch_name

There is also an alternative command to delete a remote branch, that is, at least for me harder to remember:

git push origin remote_name :branch_name

Abhinaya
  • 949
  • 1
  • 5
  • 12