1

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.

PaulBunion
  • 346
  • 2
  • 18

3 Answers3

1

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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I know it's origin's GitHub URL is correct, and I know I'm a collaborator on that project. A sent me an invite and I accepted it. This is git bash for Windows, so is there even a `.profile or .bashrc or .bash_profile`? – PaulBunion Oct 17 '18 at 05:30
  • @TheRandomSpectator can you try, just for testing, a `git push -u https://yourGitHubLogin@YourGitHubPassword:github.com/aUser/aRepo.git master`? – VonC Oct 17 '18 at 05:36
  • Still gave a `fatal` error, but this time it was different. `fatal: unable to access 'http://myGHLogin@myGHPassword:github.com/aUser/aRepo.git/': Port number ended with 'g'` – PaulBunion Oct 17 '18 at 06:24
  • @TheRandomSpectator Sorry try login:password@github, not login@password:github – VonC Oct 17 '18 at 06:54
  • Got `remote: Invalid username or password` in addition to the `NullReferenceException` error again (see question). Just to be clear, I'm using _my_ login info and _A's_ username and repo. That's correct, correct? – PaulBunion Oct 17 '18 at 14:12
  • @TheRandomSpectator Yes, it is correct. Does your password has any special character? – VonC Oct 17 '18 at 15:35
  • It's a randomly generated pw, so yes. – PaulBunion Oct 17 '18 at 15:56
  • 1
    @The then you need to percent encode it: https://stackoverflow.com/a/35195690/6309 – VonC Oct 17 '18 at 16:30
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/182060/discussion-between-therandomspectator-and-vonc). – PaulBunion Oct 18 '18 at 03:38
  • Thanks for the help. Unfortunately, I get the same result as when not percent encoding the pw. – PaulBunion Oct 18 '18 at 03:39
  • @TheRandomSpectator Can you ask the owner of that repo to register a public SSH key, and switch to SSH, to check if you can access the repo that way? Don't use a passphrase. https://gist.github.com/cybersamx/1ad243b47cb0ac6734d2 – VonC Oct 18 '18 at 04:36
  • Problem solved. It was that I didn't have a PAT set up (https://stackoverflow.com/questions/17659206/git-push-results-in-authentication-failed - I see you posted here as well). – PaulBunion Oct 18 '18 at 17:20
1

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
PaulBunion
  • 346
  • 2
  • 18
-1

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

Bill
  • 132
  • 1
  • 1
  • 10
  • This is a comment, not an answer. – castis Oct 17 '18 at 00:46
  • No. I said I'm working in git bash for all the actual git stuff, but my IDE is Eclipse. Yes, I know I could be doing git in Eclipse, but I said I'm having the same issue in Eclipse. – PaulBunion Oct 17 '18 at 00:52