user2775042
user2775042

Reputation: 509

Removing remote Git branch using JGit

I am trying to remove a remote branch called test. I don't get any errors while running this code but the remote branch is not getting removed.

'ans' is the destination including the branch id.

This code worked for me when I used the full branch. but I must have changed something because it doesnt work any more.

git.branchDelete().setBranchNames(ans).setForce(true).call();
RefSpec refSpec = new RefSpec()
        .setSource(null)
        .setDestination("refs/remotes/origin/test");
git.push().setRefSpecs(refSpec).setRemote("origin").call();

Upvotes: 2

Views: 1390

Answers (1)

Rüdiger Herrmann
Rüdiger Herrmann

Reputation: 20985

Assuming that 'ans' is the full branch name of the local branch e.g. refs/heads/test the branchDelete() code looks ok.

But the destination of the ref spec that is pased to the push command should denote the name of the branch as it is referenced on the remote end. In this case refs/heads/test

RefSpec refSpec = new RefSpec().setSource(null).setDestination("refs/heads/test");

or in short

RefSpec refSpec = new RefSpec(":refs/heads/test");

Upvotes: 3

Related Questions