Why I don't get the error "fatal: The current branch A has no upstream branch."

Viewed 1510

It's about why I do not get the error "fatal: The current branch A has no upstream branch."

I deleted the REMOTE branch A with the command git push origin :A . Then I switched to LOCAL branch A with the command git checkout A . After adding, commiting and pushing, I don't get the error "fatal: The current branch A has no upstream branch."

Why does this error not appear even though the remote branch A does not exist because I deleted it before?

2 Answers

Because the error you expect to have is not related to the existence or not of the branch in the remote. It is related to the fact that your local branch has a "destination" defined ("upstream branch").

When you delete the remote branch, you don't unset the upstream branch from your local branch.

Your local branch can have a upstream branch defined that doesn't exist yet/anymore.

Even when you deleted the remote branch, your local repository still has the configuration for your local branch to point to a specific remote branch. You can check this configuration by looking in the file .git/config. You should see an entry like the following, just with your branch name:

[branch "master"]
    remote = origin
    merge = refs/heads/master
Related