fatal: The current branch master has no upstream branch

Question:

I’m trying to push one of my projects to GitHub, and I keep getting this error:

So I tried it and got this:

Another stackoverflow thread suggested I try the following, with disappointing results.

Then I tried this:

Any hints?

Answer:

You fixed the push, but, independently of that push issue (git push -u origin master or git push -u origin --all), you need now to resolve the authentication issue.

That depends on your url (ssh as in ‘git@github.com/yourRepo, or https as in https://github.com/You/YourRepo)

For https url:

If your account is protected by the two-factor authentication, your regular password won’t work (for https url).

Same problem if your password contains a special character

If https doesn’t work (because you don’t want to generate a secondary key, a PAT: personal Access Token), then you can switch to ssh.

You can automatically create the branch of the same name on the remote with:

Why?

  • HEAD (see your .git\HEAD file) has the refspec of the currently checked out branch (for example: ref: refs/heads/master)
  • the default push policy is simple

Since the refpec used for this push is head: (no destination), a missing :<dst> means to update the same ref as the <src> (head, which is a branch).

That won’t work if HEAD is detached though.

Leave a Reply