Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fatal: The current branch master has no upstream branch

Tags:

git

github

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

peeplesoft@jane3:~/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:

peeplesoft@jane3:~/846156 (master) $ git push --set-upstream origin master  fatal: Authentication failed 

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

peeplesoft@jane3:~/846156 (master) $ git push -u origin master  fatal: Authentication failed 

Then I tried this:

peeplesoft@jane3:~/846156 (master) $ git config remote.origin.push HEAD  peeplesoft@jane3:~/846156 (master) $ git push  fatal: Authentication failed 

Any hints?

like image 738
user1524361 Avatar asked May 01 '14 03:05

user1524361


People also ask

How do you solve the current branch has no upstream branch?

Fatal Git Error: Current branch has no upstream The simple solution to the current problem is easily solved by issuing the following Git push upstream command: git@upstream-error /c/branch/push (new-branch) $ git push --set-upstream origin new-branch Enumerating objects: 3, done.

What does it mean if a branch has no upstream branch?

The fatal: The current branch master has no upstream branch error occurs when you have not configured git in such a way that it creates a new branch on the remote. Therefore, you are only creating a new branch on the local computer.

How do I get upstream branch?

The easiest way to set the upstream branch is to use the “git push” command with the “-u” option for upstream branch. Alternatively, you can use the “–set-upstream” option that is equivalent to the “-u” option. As an example, let's say that you created a branch named “branch” using the checkout command.

How do I change my current branch to upstream?

Set Upstream Branch using Git Push command When the current branch i.e ('new_branch') has no Upstream branch set and we try to run the command “Git push”. After running the below command in cmd: Now, you need to set the upstream branch using the Git push command with the -u option.


1 Answers

You fixed the push, but, independently of that push issue (which I explained in "Why do I need to explicitly push a new branch?": 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 '[email protected]/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), as explained here or here.

Same problem if your password contains special character (as in this answer)

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, as I have shown here.


As noted by qwerty in the comments, you can automatically create the branch of same name on the remote with:

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.

like image 144
VonC Avatar answered Oct 01 '22 05:10

VonC