31

we are using git in Team Foundation Service, and we are trying to find a way to delete a remote branch by running the following command.

git push origin --delete TheBranchName

The remote server keep rejecting with following error

 ! [remote rejected] TheBranchName (TF401026: The ForcePush permission is required to perform this action.) error: failed to push some refs to 'https://xxx.visualstudio.com/DefaultCollection/_git/Xxxxxx'

any idea how to set correct permission to a user in TFS?

1
  • 3
    It seems that you don't have enough rights to do this operation. The command is right btw
    – iberbeu
    Mar 6, 2013 at 22:20

7 Answers 7

23

The security options can be accessed for the repositories at
1. Code->Explorer
2. Select a repo form the Explorer
3. At the details of the repository, you should click to the name of the repository beside the explorer.
4. Select the Manage repositories... menu

Here you can configure the rights of each contributor groups and individual users for repositories and their branches. "Rewrite and destroy history (force push)" option shound be Allow or Inherited Allow to be able to force push.

1
  • I had to explicitly add myself and give myself that permission, and it worked. Feb 22, 2018 at 21:01
8

To delete a remote branch you can use:

git push origin :TheBranchName
1
  • 1
    I tried "git push origin --delete BranchName" and got an error that I didn't have the required permissions - then I followed your advice with the "git push origin :BranchName" and that prompted me for my credentials, and then worked! How/why does this work?
    – Omaer
    Oct 19, 2016 at 13:09
3

From the git push man-page:

-f
--force
    Usually, the command refuses to update a remote ref that is not an ancestor of the
    local ref used to overwrite it. This flag disables the check. This can cause the
    remote repository to lose commits; use it with care.

Looks like the branch you are trying to delete is not an ancestor of the branch you are on -- add this --force argument and see if it helps.

0
3

I would like to edit Ursegor answer but I lack the reputation to do so.

In version 14.102.25423.0 (Team Foundation Server 2015 Update 3) the security/permissions options can be accessed for the repositories at:

  1. Code/Explorer
  2. Select a repository from the Explorer
  3. Click the three dots ... beside the repositoy name.
  4. Select Security
2

In the first answer and the first comment of this link is answered your question:

"Someone has enabled a hook in the remote repo that is prohibiting the delete -- this is usually done so that someone can't push a rebased branch into the repo. (I maintain a fairly large collection of git repositories and they are all configured this way, although not with a hook.)

Look in the hooks/ directory in the remote repository. There will be a script named "update"; this is what's refusing to let you delete the branch."

1
  • 1
    The question refers to TFS, which doesn't support remote hooks. Well, it does, but not through the hooks/ directory - you have to write a TFS event handler e.g. almsports.net/… Jul 2, 2015 at 11:52
1

I landed on this question searching for a way to delete a branch in VSO. For anyone else who lands here, I have a process which is a little cumbersome, but works. Create a pull request from the branch. Once the pull request is created, abandon it. Once you abandon the request, you are presented with a delete source branch button. Click that to delete the branch.

1
  • It would be good if it worked. I just tried - after clicking Abandon, there is only Reactivate button and no any "Delete" options. Jun 7, 2016 at 8:41
0

I just had to open the Git UI tool, open the repo and deleted the branch from there and it worked fine. I couldn't do it from TFS.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.