I too had the same problem, I managed to solve it after hours of work. Now I share with you how I managed it 🙂. I found two methods to solve this problem, I hope at least one of them works for you! But before I explain the solution that worked for me, I'll explain step by step what the problem is:
IF EVERYTHING WORKED:
If everything worked (as it should), after running the command:
git push -u origin main
a new small window would appear for entering the GitHub username and password, this is because basically Git asks GitHub for permission to make changes.
This "window" is the Credential Helper.
CAUSE OF THE PROBLEM:
So the problem you're experiencing is due to an authentication issue.
This problem mainly occurs when you install Git:
we all tend to click on the "next" button to leave the default settings unchanged, without paying much attention to what is being asked of us.
During Git installation, in fact, we are asked to choose the "Credential Helper"! During the installation of the latest version of Git, there is a default setting that didn't work for me at all. So I'm inclined to think that those who install the new version of Git may run into this problem (probably for Windows users).
SOLUTIONS:
- 1. First Method
Uninstall Git: I know it's a hassle because you have to reconfigure everything but if you want to avoid uninstalling Git then I suggest you skip this method and look at the second method.
So I repeat, uninstall Git. When you reinstall it, be especially careful when it asks you to choose the Credential Helper. Change the default setting, choose "Git Credential Manager", as you can see from the picture:
click here to see the photo
(in fact, if you notice, it says that it handles credentials for GitHub)
Continue with the installation. Now your problem should not occur again.
- 2. Second Method
To solve the problem, another method is to run the following command:
git config remote.origin.url https://USERNAME:[email protected]/USERNAME/REPONAME.git
In this way, you would not only solve the problem without the help of the Credential Helper, but you would also save your Github username and password on Git: this way you would no longer need to enter your username and password every time you need to save your code on Github.
That is why I integrated both methods for my problem.
- Other methods??
There will probably be other methods to solve the same problem. If you're using windows, one of these might be to open the Credential Manager on Windows (search by typing this name into the search bar) and from there somehow enter your GitHub username and password. This is a way that I have not followed honestly, that I discovered late and I do not know if it works or not, I wanted to share it with you anyway.
I hope I have been of help to some of you. 🙂