Cannot reuse an old branch prefix as a branch name (BB-11256)

Issue #9288 open
Mark van den Berg created an issue

Some time ago I pushed a branch called 'dev/some_feature' to a Bitbucket repository. Now I've decided that I want to group my feature branches not with a 'dev/' prefix but with 'feature/', and I want to use a branch called 'dev' as the integration branch with all finished changes.

So I merged and deleted all 'dev/*' branches on Bitbucket and locally. I then created a local 'dev' branch (branching off of the 'master' branch). Now if I try to push this branch to Bitbucket (remote 'origin'), I get the following error:

 ! [remote rejected] dev -> dev (failed to write)
error: failed to push some refs to 'https://mjpvandenberg@bitbucket.org/xxx/xxx.git'

My guess is that, although all 'dev/*' branches have been deleted, there's still a 'dev' folder in .git/refs/heads. I am not aware of any method by which to actively remove this folder, either thru the web interface or with any git-remote command. I don't know how often git-gc runs on Bitbucket and if it will fix this issue. If I use the web interface to create a new branch off of 'master' directly in the Bitbucket repo, the error message says 'Invalid branch name'.

It would be nice if Bitbucket could see that the 'dev' branch name is in fact available.

Comments (42)

  1. Nicolas Venegas

    Hi

    For what repository do you want us to check this on? Maybe you can email support@bitbucket.org with the details if you don't want to say here.

    Cheers

    Nicolas

  2. Nicolas Venegas

    There doesn't seem to be a dev directory under heads in your repository on our server:

    $ ls --color=never -R refs
    refs:
    heads  tags
    
    refs/heads:
    master  modules
    
    refs/tags:
    $
    
  3. Nicolas Venegas

    Ah, looks like there are still reflog entries:

    $ file `find . -name 'dev'`
    ./logs/refs/heads/dev: directory
    
  4. Nicolas Venegas

    OK, I've made a backup of your repository and then removed those reflog entries from our server. Can you try pushing again, please?

  5. Harry Ho

    Thanks John, we put in a ticket last night. I think you guys are in the process of doing something for us.

  6. Brian Youngblood

    same issue here. not able to recreate a branch that was removed - in this case "release" was removed and not able to add it again without getting the "Invalid branch name." error.

  7. John Garcia

    If you're affected by this issue, go ahead and post the owner, repository, and branch info here on this public issue and I'll clear it out for you. Or you can file a private issue at support.atlassian.com

  8. David Chua

    Hi John, we are having the same problem.

    owner: shopback (team)

    repo: shopback.com-admin

    branch: release

  9. Alejandro Magnorsky

    @jgarcia4 , @Nicolas Venegas

    • owner: onitmedia
    • repos: muulla_api, muullamobileclient, muullacms
    • branch: production/dealhound can't be created because there are previous branches that looks like production/dealhound/1.00.17, production/dealhound/1.00.18

    Thanks

  10. Adam Haid

    owner: solidfire repo: solidfire-powershell branch: release

    Please delete the "release" branch as it's preventing me from creating release/v1.0.1.0

  11. André Tzermias

    We also have been having problem with this issue, on branch develop. Can someone help us out?

  12. Manish Das

    @André Tzermias We had to file a ticket to their Bitbucket support team. There must directory on BB, which is causing this. After they remove that directory, you should be good to go.

  13. Manish Das

    @André Tzermias You are welcome! I wish, there was a way we could do that, it's lame filing ticket for this every time it happens. We have another repo where we have similar issue and now we will have to file a ticket for that as well. :/

  14. Chengjie Liu

    We ran into this as well. This is workaround we used to workaround problem. No need for us to file support ticket.

    • Switch to git ssh clone. Set up ssh key too. git clone git@bitbucket.org:company/gitrepo.git
    • Recreate new branch with same name from ssh cloned repo, ghostbranch in this example. git push origin master:ghostbranch
    • Delete branch again from ssh cloned repo. git push origin :ghostbranch
    • Now you can create a new branch that uses name as prefix git push origin master:ghostbranch/test

    In the end https server is a wrapper of real git developed by bitbucket. It might have a bug not cleaning up file in .git/logs/refs/heads/ghostbranch. Ssh git does this correctly.

  15. Kaleb Elwert

    This is copied from another bug:

    When you select 'close branch after the pull request is merged' and the merge the pull request the reflog is not being cleaned up. This means that any future branches with that name as path prefix cannot be successfully pushed to due to a git error.

    Steps to reproduce:

    1. Create a branch from master called "foo"
    2. Create a commit on foo and push it to Bitbucket
    3. Create a PR from foo to master, selecting close branch after merge
    4. Merge the PR
    5. Create a branch locally called "foo/my-new-branch-name"
    6. Attempt to push a commit to "foo/my-new-branch-name" on bitbucket

    You will see an error from git that looks something like error: unable to create directory for ./logs/refs/heads/foo/my-new-branch-name

  16. Felipe Faraggi

    We've got this problem as well, although the bitbucket staff was very quick to repsond to our request to delete the ref log file.

  17. Sean Farley

    This has finally been fixed in git with the newest version (2.13):

    • Deletion of a branch "foo/bar" could remove .git/refs/heads/foo once there no longer is any other branch whose name begins with "foo/", but we didn't do so so far. Now we do.

    I'll work with @Erik van Zijst to try and update our version on Bitbucket.

  18. Erik van Zijst

    Note that in the meantime, anyone who runs into this can contact support@bitbucket.org, refer to this issue and get those old directories removed.

  19. Log in to comment