Git push fails: Refusing to delete current branch

I’m trying to set my system up so that I can publish to github from terminal, but I can’t get a git push to go through.

The error is: ! [remote rejected] main (refusing to delete the current branch: refs/heads/main)

I wonder why push is trying to delete the branch? I guess maybe it’s trying to delete the current branch so it can upload the new one, but yikes.

I’ve followed a few different tutorials to set everything up, and I think it’s set up right. Everything to this point works fine. I’ve looked around and read a few things, but none of it seems to apply to my situation. Most of it is about not being able to delete the branch, which is not what I’m trying to do anyway.

So what’s the trick to be able to push my changes to github?

What exact command gave you that error message? It is possible to push branch deletion, so maybe something doesn’t work quite like you expect it to.

1 Like

The command is
git push <repository>

I really can’t imagine why it is trying to delete anything unless it’s intentionally coded that way. It’s a brand new git repo with a test file in it.

I’ve tried removing and re-adding the remote source, and even recreating the git repo, but I keep getting the same error.

:wave: Welcome!

I wonder how your branches are set up. Can you run these commands in your local git folder/repository and paste the output here?

git branch
this should show us the branch(es) set up in your local git repository

git branch -r
this should list the branch(es) that exist in your remote.

1 Like

Thank you! :slight_smile:

I was thinking about this last night. I know where you’re going, and you’re absolutely right! This problem is because I set the remote branch as a mirror. I’m not sure what that does in the git world, but it seems to not do what I want.

Removing and re-adding the remote without the mirror option gets me past this error (but on to others unfortunately).

Interestingly, git branch -r did not return any output. Perhaps this is also because of the mirror option, but it is technically incorrect in my opinion, because there is a remote source set up.