Eatdoku
Eatdoku

Reputation: 6931

Git delete remote branch in TFS git repository

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?

Upvotes: 31

Views: 27165

Answers (7)

inwenis
inwenis

Reputation: 409

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

Upvotes: 3

Flea
Flea

Reputation: 11284

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.

Upvotes: 0

Prof Von Lemongargle
Prof Von Lemongargle

Reputation: 3768

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.

Upvotes: 1

Ursegor
Ursegor

Reputation: 878

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.

Upvotes: 23

Winner Crespo
Winner Crespo

Reputation: 1704

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."

Upvotes: 2

MrDustpan
MrDustpan

Reputation: 5528

To delete a remote branch you can use:

git push origin :TheBranchName

Upvotes: 8

David Culp
David Culp

Reputation: 5480

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.

Upvotes: 3

Related Questions