Question:
I’m trying to push one of my projects to GitHub, and I keep getting this error:
1 2 3 4 5 6 |
cloudaffaire@debjeet:~/846156 (master) $ git push fatal: The current branch master has no upstream branch. To push the current branch and set the remote as upstream, use git push --set-upstream origin master |
So I tried it and got this:
1 2 3 |
cloudaffaire@debjeet:~/846156 (master) $ git push --set-upstream origin master fatal: Authentication failed |
Another stackoverflow thread suggested I try the following, with disappointing results.
1 2 3 |
cloudaffaire@debjeet:~/846156 (master) $ git push -u origin master fatal: Authentication failed |
Then I tried this:
1 2 3 4 5 6 |
cloudaffaire@debjeet:~/846156 (master) $ git config remote.origin.push HEAD cloudaffaire@debjeet:~/846156 (master) $ git push fatal: Authentication failed |
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:
1 |
git push -u origin head |
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.