-1

Question: is there a way to delete remote branches without merging them in?

Background: We had a third party do some work for us they use GitHub and we do also

So I pulled from there repo and pushed to ours. Unfortunately, I pushed to the wrong repo. So now we have a project with this other project in it.

We do not really want to merge in all the changes and delete them and have the history remain. I would just like to delete this branch(push).

I have tried -git push origin --delete branchName (of course this will only work if its merged in.)

It looks like the only way to delete a nonmerged branch is with -D -git branch -D branchname (but this only works on the local repo)

is there a way to delete branches without merging them on a remote repository or any other way to clean this mess up? (one repo pushed to another no merge)

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
User
  • 41
  • 1
  • 7

1 Answers1

1
git push origin :branchName

always works for me.

Fred Foo
  • 355,277
  • 75
  • 744
  • 836
  • 3
    This is perfectly correct, but just for the record: the syntax for pushing branches is git push remote-name local-branch:remote-branch. For deletion, the idea is that you're pushing *nothing* into remote-branch, updating remote-branch into nothing. Knowing the logic behind it may help people remember it. – SáT Dec 07 '12 at 19:43
  • @SáT: thanks, I didn't know that. I just treated it as Git magic. – Fred Foo Dec 07 '12 at 19:57
  • I can push to the remote fine but to delete this branch and everything with it without merging is the problem. Maybe I am missing something here? – User Dec 07 '12 at 19:59
  • @user1886208: maybe you're missing the colon before branchName? :) Try it, it should work. It's an awkward syntax for sure, but that's the way it is. If it doesn't work, you may try git push origin : branchname --force, but it shouldn't be needed. Also, you may want to check out [this](http://git-scm.com/book/ch3-5.html) and [this](https://help.github.com/articles/remove-sensitive-data) -- the latter contains dangerous stuff, so be careful (you may want to test these out in a dummy repo). – SáT Dec 07 '12 at 20:23
  • @user1886208: is there an error message? What happens when you try it? – SáT Dec 07 '12 at 20:55
  • $ git branch -D master -> Deleted branch master (was 16bc001). -> $ git branch push :master -> Fatal: Not a valid object name: ':master' – User Dec 07 '12 at 21:04
  • @user1886208: that's `git push`, not `git branch push`. – Fred Foo Dec 07 '12 at 22:53
  • Still no luck getting error -> remote: error: refusing to delete the current branch: refs/heads/master To git@github.com:***/***.git ! [remote rejected] master (deletion of the current branch prohibited) error: failed to push some refs to git@github.com:***/***.git' – User Dec 08 '12 at 00:28