Delete branches in Bitbucket

前端 未结 12 1605
执念已碎
执念已碎 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:43

    In Android Studio, the options down the right corner of the IDE:

    • Change/checkout other local branch
    • Delete unwanted local branches (i.e. v0.0.1...)
    • Delete unwanted remote branches (i.e. origin/v0.0.1...) -- this step will delete branches in BitBucket if the branches are not prevented to be deleted and they are not the MAIN BRANCH.
    0 讨论(0)
  • 2020-12-22 17:44

    For deleting branch from Bitbucket,

    1. Go to Overview (Your repository > branches in the left sidebar)
    2. Click the number of branches (that should show you the list of branches)
    3. Click on the branch that you want to delete
    4. On top right corner, click the 3 dots (besides Merge button).
    5. There is the option of "Delete Branch" if you have rights.
    0 讨论(0)
  • 2020-12-22 17:45

    Try this command, it will purge all branches that have been merged to the develop branch.

    for i in `git branch -r --merged origin/develop| grep origin | grep -v '>' \
       | grep -v master | grep -v develop | sed -E "s|^ *origin/||g"`; \
    do \
       git push origin $i --delete; \
    done
    
    0 讨论(0)
  • 2020-12-22 17:48

    In addition to the answer given by @Marcus you can now also delete a remote branch via:

    git push [remote-name] --delete [branch-name] 
    
    0 讨论(0)
  • 2020-12-22 17:52

    I've wrote this small script when the number of branches in my repo exceeded several hundreds. I did not know about the other methods (with CLI) so I decided to automate it with selenium. It simply opens Bitbucket website, goes to Branches, scrolls down the page to the end and clicks on every branch options menu -> clicks Delete button -> clicks Yes. It can be tuned to keep the last N (100 - default) branches and skip branches with specific names (master, develop - default, could be more). If this fits for you, you can try that way.

    https://github.com/globad/remove-old-branches

    All you need is to clone the repository, download the proper version of Chrome-webdriver, input few constants like URL to your repository and run the script.

    The code is simple enough to understand. If you have any questions, write comments / create an Issue.

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

    If you are using a pycharm IDE for development and you already have added Git with it. you can directly delete remote branch from pycharm. From toolbar VCS-->Git-->Branches-->Select branch-->and Delete. It will delete it from remote git server.

    0 讨论(0)
提交回复
热议问题