Here is the situation, I cloned a repository from some server and start to work on local, everything was fine until I have to send all my work to prod on this server. From the server, I pulled all the code from my Github repo, some conflicts were found and I fixed, everything well until I pushed all these changes to my Github repo from the server. I was prompted to insert my Github username and password, but it didn’t work!!
This was the error I got:
$ git Push Origin master Username for 'https://github.com': fernastereo Password for 'https://email@example.com': remote: Invalid username or password. fatal: Authentication failed for 'https://github.com/fernastereo/the_repo.git/'
Ok, what is going on here??? I know my username, I know my password, what is wrong then??
The thing is I was using https URL and, according to Github, when you enable 2FA, you must insert a personal access token instead of 2FA code and your Github password. Ok, not a big deal. But, How can I generate this access token?? Let’s see…
On Github, click your profile photo, then click Settings.
Click on Developer settings from the sidebar on the left.
Click on Personal access tokens. (again, sidebar on the left)
Click Generate new token.
Write a descriptive note for your token and select the scopes or permissions, you’d like to grant. To use your token to access repositories from the command line, select repo.
Click on Generate Token and copy the token to your clipboard, since you will not be able to see the token again.
Now, with the access token, I tried to push again my changes to my Github repository, one more time, I was prompted to insert my Github username and password, but this time instead of writing my password I paste the access token I had created before and voilà!!! Problem solved!!!