Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delete remote branch #74

Open
accfcx opened this issue Mar 24, 2020 · 2 comments
Open

delete remote branch #74

accfcx opened this issue Mar 24, 2020 · 2 comments

Comments

@accfcx
Copy link

accfcx commented Mar 24, 2020

How to delete remote branch with JGit? I search over Google and text following code.

   git.branchDelete()
            .setBranchNames(fullBranch)
            .call();

    RefSpec refSpec = new RefSpec()
            .setSource(null)
            .setDestination(fullBranch);

    git.push()
            .setRefSpecs(refSpec)
            .setRemote("origin")
            .call();

but it does not work at all. It just deletes local branch.

@centic9
Copy link
Owner

centic9 commented Apr 16, 2020

I fear the Git protocol does not allow this, you may need to delete the branch locally and then push that deletion to the remote repository.

However I am not sure about how to do this actually, sorry. Please also note the statement in the README and in new-issue screen, duplicated below again.

Therefore I am closing this, please ask on stackoverflow to get more people to take a look and comment.

Note: Please use sites such as http://stackoverflow.com for general questions about JGit usage, not issues in this project. Issues should be used for problems with snippets and suggestions of missing snippets. Snippets from good answers on stackoverflow can then be included here, naturally.

@centic9 centic9 closed this as completed Apr 16, 2020
@jmini
Copy link
Contributor

jmini commented Nov 29, 2021

The idea of snippet presented in this issue works well. I got the same from:

https://stackoverflow.com/questions/11892766/how-to-remove-remote-branch-with-jgit


I guess #74 (comment) the value of fullBranch variable is not correct.

If the branch is named testbranch, what is presented in CreateAndDeleteBranch.java in this project will delete the local branch:

git.branchDelete()
.setBranchNames("testbranch")
.setForce(true)
.call();

Then this will delete the local pointer we have of the branch in the distant repository:

git.branchDelete()
    .setBranchNames("refs/remotes/origin/testbranch")
    .setForce(true)
    .call();

and this will delete the branch remotely in the distant repository:

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

    git.push()
            .setRefSpecs(refSpec)
            .setRemote("origin")
            .call();

In my opinion a snippet of this cook book could contain and example for this last use-case.
Can this issue be reopened?

@centic9 centic9 reopened this Nov 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants