Yes, this was a strange scenario for me. I created Angular 2 project in Visual Studio Code and wanted to push the project into a GitHub Repository. Sounds a simple requirement right? So to publish the project to a GitHub Repository, I ran following 5 commands in the order given below:
- git init
- git add –A
- git commit –m “commitmessage”
- git remote add origin “Url of GitHub Repo”
- git push origin master
For the push command, I got the error as shown in the image below. Focus on error message for user djinfragistics
Error message is very clear that user djinfragistics does not have access to the remote repository hence HTTP Error code 403 is returned from the GitHub server.
To check current user name for the project I ran the command
- git config user.name
- git config user.email
As shown in the image below, I found username and user email was set to the user which had access to remote repository.
I was confused and was not able to figure it out that why git command is not taking user from the current project and taking some random user djinfragistics. I thought might be global user is set to djinfragistics. So, to check that I ran the command as below
- git config –global user.name
- git config –global user.email
As shown in the image below, I found username and user email was set to the user which had access to remote repository.
It was strange, that global user is also set to the different user, however to publish project, git was taking some strange user djinfragistics from somewhere.
After bit of researching, I found that on windows when we install git 2, Credential Manager also gets installed. It runs as a daemon process and caches the git user credentials, such that each time we do not have to provide user information to push the changes to GitHub repository.
In my scenario, I might have used djinfragistics username earlier on the same system and that user got cached in Credential Manager. So even though user was set to debugmode, on running the command git was taking user djinfragistics from credential manager.
To check various options, run the command as shown below
- git credential-manager
Above command will show us all options of credential manager. I was lazy and wanted to publish project as early as possible, so I ran
- git credential-manager uninstall
The above command will uninstall credential manager and we will have to provide git user credential each time. I would recommend you to explore various options and edit the file rather uninstalling it.
It solved my problem and git command started taking correct user name. I hope it helps.
Leave a Reply