简体   繁体   中英

Can't push to GitHub repository; unauthroized

I'm pretty new to git, but even from all the searching I've done, this still seems like a really abnormal situation.

I'm working on a school project with three other people, and we're all working off the same repo owned by A. B and C have no issue pushing to the repo and have never had to enter credentials, but every time I try to push, git (using git bash if that matters) gives an error ( fatal: NullReferenceException encountered. Object reference not set to an instance of an object. ) and then asks for " http://github.com/ " username and password. I have tried it with both my credentials and A's credentials, but it always says I am unauthorized (even when trying to push in Eclipse).

According to git remote show origin I am properly attached to the right repo, and pulling wont help (which seems to work ok) because with all my troubleshooting/testing, my local master is 8 commits ahead of the remote master.

I'm trying to give as much detail as possible, but I'm still not super familiar with git, so I'm probably leaving something out. I'll probably be watching this thread fairly closely though.

You must check that your origin is a proper GitHub URL

https://github.com/aUser/aProject

or:

git@github.com/aUser/aProject

Then make sure you are a collaborator on (or the owner of) that project.

Check in your bash session your .profile or .bashrc or .bash_profile : its content could also trigger an error.

In the end, the issue was that I am using 2FA on github, so I couldn't just directly sign in with my password. I had to first create a personal access token which you can read about here .

Next I stored this by disconnecting the origin, then re-adding it using the https URL, and using the personal access token as the password, and this permanently stored the credentials.

git remote remove origin
git remote add origin https://myUsername:P.A.T.@github.com/aUsername/aRepo.git
git push --set-upstream origin master

Are you working in Visual Studio? If so In VS, go to the View menu > Other Windows > Command Run “Tfs.tfc trace /start /logfile:C:\\sometempdir\\log.txt /keywords:TFS.All=4” to capture the logs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM