'fatal: The current branch master has no upstream branch

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?



Solution 1:[1]

Also you can use the following command:

git push -u origin master

This creates (-u) another branch in your remote repo. Once the authentication using ssh is done that is.

Solution 2:[2]

If you define the action git push it should take it if no refspec is given on the command line, no refspec is configured in the remote, and no refspec is implied by any of the options given on the command line.

Just do it:

git config --global push.default current

then

git push

Solution 3:[3]

Apparently you also get this error message when you forget the --all parameter when pushing for the first time. I wrote

git push -u origin

which gave this error, it should have been

git push -u origin --all

Oh how I love these copy-paste errors ...

Solution 4:[4]

Please try this scenario

git push -f --set-upstream origin master

Solution 5:[5]

You need to configure the remote first, then push.

git remote add origin url-to-your-repo

Actual Instructions

Solution 6:[6]

use this command first before you push in to the branch

git config --global push.default current

After executing the above command use git push command.

Solution 7:[7]

on a very simple side, once you have other branches, you can't just use for pushing a branch

git push

But you need to specify the branch now, even if you have checkout the branch you want to push, so

git push origin <feature_branch>

Where can be even the master branch

Solution 8:[8]

Well, I was having the same trouble while uploading and I resolved it by doing the same thing which it says to do: Earlier I was trying to push through terminal to my repository in linux by https like

git push https://github.com/SiddharthChoudhary/ClientServerCloudComputing.git

But was not getting any result and hence I went down deeper and tried:

git push --set-upstream https://github.com/SiddharthChoudhary/ClientServerCloudComputing.git master

And it worked. Thus then you will get prompted with username and password. I also generated a token and instead of Password I pasted the token and thus, being done successfully.

  1. To generate a token go to your Github account and in Developer Settings and then create another token.
  2. After getting that, copy that token and paste in the password prompt when it's been asked.

Solution 9:[9]

I made the simple error of forgetting to commit:

git commit -m "first commit"

then git push origin master worked.

Solution 10:[10]

It means that you don't have your branch(the branch that you want to push) in your remote repository, in other words it does not exist in your remote repository(it wasn't created yet)... So use this Code:

git push -u origin 'your branch name'

this code will create your branch in your remote repository and will push it...

Solution 11:[11]

I had the same problem

enter image description here

I resolved it that used below command

$ git branch --set-upstream develop origin/develop

and it will add a config in the config file in the .git folder.

enter image description here

Solution 12:[12]

First use git pull origin your_branch_name Then use git push origin your_branch_name

Solution 13:[13]

There is a simple solution to this which worked for me on macOS Sierra. I did these two commands:

git pull --rebase git_url(Ex: https://github.com/username/reponame.git)
git push origin master

If it shows any fatal error regarding upstream after any future push then simply run :

git push --set-upstream origin master

Solution 14:[14]

If you constantly get the following git error message after attempting a git push with a new local branch:

fatal: The current branch has no upstream branch.

To push the current branch and set the remote as upstream, use

git push --set-upstream origin <branchname>

Then the issue is that you have not configured git to always create new branches on the remote from local ones.

The permanent fix if you always want to just create that new branch on the remote to mirror and track your local branch is:

git config --global push.default current

Now you can git push without any errors!

https://vancelucas.com/blog/how-to-fix-git-fatal-the-current-branch-has-no-upstream-branch/

Solution 15:[15]

For me, it was because I had deleted the hidden .git folder.

I fixed it by deleting the folder, re-cloning, and re-making the changes.

Solution 16:[16]

Encountered just about the same problem, but not from the master branch. I tried to push two (2) branches to my remote repository, by using the $ git push command; which unfortunately threw up the:

fatal: The current branch <branch-name> has no upstream branch. To push the current branch and set the remote as upstream, use

 git push --set-upstream origin <branch-name>

I got it fixed with this command below:

$ git push -u origin --all

PS: The solution provided here should, i believe, make it easier for git to track out branches remotely; this could come in-handy someday, when working on projects with couple of branches.

Solution 17:[17]

1. A computer and your github associated. Use SSH. Computer code so you do not need to submit verified enter image description here

2. git can not manage empty folder. So you have to write such a readme.md saved in a file. Otherwise you will not find the file.

3. Your local project is nothing new projects move over. Please

git init

git remote add origin +"githublink"

git add .

git commit -m "" go again.

4. then git pull origin master (the key)

5. At last git push origin master (solve all problem).

http://my.oschina.net/psuyun/blog/123005 ????

Solution 18:[18]

If you are trying to push your code direct to the master branch then use command

git push origin master

It helps me.

Solution 19:[19]

I also got the same error.I think it was because I clone it and try to push back. $ git push -u origin master This is the right command.Try that

Counting objects: 8, done. Delta compression using up to 2 threads. Compressing objects: 100% (4/4), done. Writing objects: 100% (8/8), 691 bytes | 46.00 KiB/s, done. Total 8 (delta 1), reused 0 (delta 0) remote: Resolving deltas: 100% (1/1), done.

  • [new branch] master -> master Branch master set up to track remote branch master from origin.

    It was successful. Try to create new u branch 
    

Solution 20:[20]

I had the same problem, the cause was that I forgot to specify the branch

git push myorigin feature/23082018_my-feature_eb

Solution 21:[21]

For me, I was pushing the changes to a private repo to which I didn't had the write access. Make sure you have the valid access rights while performing push or pull operations.

You can directly verify via

Solution 22:[22]

If you are on any branch, you can use this:

git push origin head -u

This will automatically create new branch of the same name on the remote.

Solution 23:[23]

commit your code using

git commit -m "first commit"

then config your mail id using

git config user.email "[email protected]"

this is work for me

Solution 24:[24]

The thing that helped me: I saw that the connection between my directory to git wasn't established - so I did again: git push -u origin main

Solution 25:[25]

Different case with same error (backing up to external drive), the issue was that I'd set up the remote repo with clone. Works every time if you set the remote repo up with bare initially

cd F:/backups/dir
git init --bare
cd C:/working/dir
git remote add backup F:/backups/dir
git push backup master

Solution 26:[26]

In my mind, this is just a wrong default git behavior. Having reviewed all options support by git, also reviewed the relevant git code:

https://github.com/git/git/blob/140045821aa78da3a80a7d7c8f707b955e1ab40d/builtin/push.c#L188

The best solution I would suggest it simply override the push default command:

git config --global alias.pu 'push -u'

This basically changes the default behavior of push so that makes sense.

Solution 27:[27]

In my case, I have a local branch called Master, whereas master is on Github. I simply rename my Master -> master and checkout to master. And then push it. It works for me.

Solution 28:[28]

To resolve this issue, while checking out the code from git itself, u need to give the command like below:

git checkout -b branchname origin/branchname

Here, by default we are setting the upstream branch, so you will not be facing the mentioned issue.

Solution 29:[29]

For me the problem come from the name of my branch : "#name-of-my-branch", without "#" it's work fine!