可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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?
回答1:
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 '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), 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.
回答2:
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.
回答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 ...
回答4:
You need to configure the remote first, then push.
git remote add origin url-to-your-repo
Actual Instructions
回答5:
First use git pull origin your_branch_name
Then use git push origin your_branch_name
回答6:
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
回答7:
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 参考链接
回答8:
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.