Git delete branch without cloning?

 ̄綄美尐妖づ 提交于 2019-12-10 17:21:15

问题


Is there a way to delete a branch from a Git repository without doing a clone or any other sort of local copy?

Basically I'm working on a dashboard for a release pipeline and don't want to have to have any of the working project's code on the dashboards server just to delete deployed feature branches.

In case it matters, we use Atlassian Stash and not Github.

I'm looking to do something similar to:

git branch -D ssh://git@repository.com/team/project/feature/deleteme

回答1:


Easy, from any git repo

git push u://r/l +:refs/heads/branchname

and if you don't happen to have one handy, just make a trash one anywhere with e.g. git init deleteme.

Some repo administrators who've had to give push access to unreliable developers have shut off delete-by-push access, so some repos will reject that command, but it's enabled by default.




回答2:


You can use Stash REST API (branch utils). You'll need to send an authenticated (see the link for details) DELETE-request to an URL like:

/rest/branch-utils/1.0/projects/{projectKey}/repos/{repositorySlug}/branches

...with parameter name that specifies the branch you want to delete and (optional?) dryRun that, judging by the name, doesn't actually apply changes but results in a response as if the changes were applied.

Request can be issued by pretty much anything able to authenticate. curl can do that, for instance.




回答3:


You would have to write a custom git client, possibly using jgit, to do this if the Stash web interface doesn't have an option.



来源:https://stackoverflow.com/questions/31866222/git-delete-branch-without-cloning

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!