Delete branches in Bitbucket

前端 未结 12 1597
执念已碎
执念已碎 2020-12-22 16:53

I\'ve created lots of branches in one of our repositories. Those branches are for testing before it will be pulled to the master. Now I see lots of them on the list and they

相关标签:
12条回答
  • 2020-12-22 17:32

    I could delete most of my branches but one looked like this and I could not delete it:

    Turned out someone had set Branch permissions under Settings and from there unchecked Allow deleting this branch. Hope this can help someone.

    Update: Where settings are located from question in comment. Enter the repository that you wan't to edit to get the menu. You might need admin privileges to change this.

    0 讨论(0)
  • 2020-12-22 17:32

    If you like fun, then you can just go to the listing page of you branches (for example merged) and just run in the javascript console:

    document.querySelectorAll('tr td div a:first-child').forEach(function(item) { fetch('https://bitbucket.org/snippets/new?owner=<yourprofilenick>', {'credentials': 'same-origin'}).then((response) => {return response.text()}).then(function(string) { return /'csrfmiddlewaretoken' value='(.*)'/g.exec(string)[1] }).then(function(csrf) { if (!~item.innerText.indexOf('/')) return; 
     fetch(`https://bitbucket.org/!api/2.0/repositories/<your_organization_path>/refs/branches/${item.innerText}`, {headers: {"x-csrftoken": csrf}, credentials: "same-origin", method: 'DELETE'}).then(() => console.log(`${item.innerText} DELETED!`)) }) })
    

    BEFORE RUN

    • replace <yourprofilenick> with your BitBucket nick
    • replace <your_organization_path> with your organization path

    HOW IT WORKS

    First we need a page with with a CSRF token in the page source, so I choose:

    https://bitbucket.org/snippets/new?owner=<yourprofilenick>

    Then for each branch (in a branch listing) it gets CSRF token and deletes that branch.

    BEWARE

    Remeber to prevent sensitive branches before deleting in repo settings.

    It WON'T delete the main branch.

    ADDITIONAL INFO

    You have to be logged in.

    It deletes only branches visible on that page (so to delete the rest of branches you have to go to the next page).

    0 讨论(0)
  • 2020-12-22 17:36
    git push <repository> -d <branch>
    

    to get the repository, type git remote -v in command line

    0 讨论(0)
  • 2020-12-22 17:41

    Step 1 : Login in Bitbucket

    Step 2 : Select Your Repository in Repositories list.

    Step 3 : Select branches in left hand side menu.

    Step4 : Cursor point on branch click on three dots (...) Select Delete (See in Bellow Image)

    0 讨论(0)
  • 2020-12-22 17:42

    If the branches are only local, you can use -d if the branch has been merged, like

    git branch -d branch-name
    

    If the branch contains code you never plan on merging, use -D instead.

    If the branch is in the upstream repo (on Bitbucket) you can remove the remote reference by

    git push origin :branch-name
    

    Also, if you're on the Bitbucket website, you can remove branches you've pushed by going to the Feature branches tab under Commits on the site. There you'll find an ellipsis icon. Click that, then choose Delete branch. Just be sure you want to drop all the changes there!

    0 讨论(0)
  • 2020-12-22 17:42

    in Bitbucket go to branches in left hand side menu.

    1. Select your branch you want to delete.
    2. Go to action column, click on three dots (...) and select delete.
    0 讨论(0)
提交回复
热议问题