I am using git for version control and GitHub for the repository of my code development. Every git push of my work to the repository is prompted to input my GitHub username and password. I would like to avoid it for every push, but how to setup git push to use GitHub token.
Password-based authentication for Git is deprecated and you should make the push based on the token authentication. GitHub has personal access token (PAT), to use in place of a password with the command line or with the API. Below is how to generate the token and use it:
Create a token in GitHub
- Log in to GitHub and navigate to the
Settingspage as shown below:
2. Click on
3. Click on Personal Access Tokens
4. Click on
Generate new token
5. Now type in the name of the token and select the scopes, or permissions, you’d like to grant this token. Make sure you select repo to use your token to access repositories from the command line. Click
How to git push using GitHub token on the command line
Once you have a token, you can use it instead of your password when performing git push operations over HTTPS as below:
git push https://<GITHUB_ACCESS_TOKEN>@github.com/<GITHUB_USERNAME>/<REPOSITORY_NAME>.git
Note: Remember to replace
<REPOSITORY_NAME> with your token, username and repository.
Comments Leave a Comment
how can I re use a ssh key to my github?
Thank you. Really helpful!
Thank you very much. You succinctly answered a question I was searching for.
It is very helpful to me
You helped me a lot. Thank you!
Helpful. Personally I like putting a leading space in front of the command to not have the access token recorded in my history file.
Thank you very much. I was not able to push code, Now I am able to push code using above commnad.
Top thanks a lot ! 😉
Does not work….. did you test this?
How to set the github token is missing
Saved me great time thank you 🙂
Thank You Very Much for the Article, Really Helpful!!
Thank you for this very helpful article !
Crisp and clear! Thanks much..
This is completely idiotic.
This situation is driving me crazy, I generated a token after hours of trying I managed to push my data. Now that it expired I am back to the same situation. Github is shit
one time solution
I prefer the old way with a password…..
Thank you so much! This worked flawlessly
Thanks for the solution but is the an alternative way not to use the access token every time you going a push?
Thanks you saved my day!
Thank you. You made it so simple : )
Command worked without the username and not with it. So the working command is: git push https://@github.com/.git
Useful information. Thank you very much!!!
thank you for the tutorial. i wish you goodluck, and all is well.
Thanks for the help
This is a bad practice, to use the token in your URL, as it stores the token as plain text.
thanks alot this help me solve my problem
Thanks, this was so useful!
It would be useful to see how to configure git to store token instead of writing it each time you push
Nice, It really help and it made my day
thank you for this. saved my butt. 🙂
doesn’t work Windows 10 GitHub
Thank you ! Worked perfectly !
I agree with the comments of Sabina Pringle. And I think you tutorial should be included into GitHub’s website.
Direct and clean.
Yes, this article was helpful for me. Thank you.
Thanks, it was helpful. Saved me so much time
It is help for a new comer as me, providing the basic of how to use to use the PAT on github.
everything is clear
Thank you! This is only article of many of read that worked. So many articles say you can simply put the token into the place where the traditional cli prompt looks for a password. I’m sure I have pushed to github since passwords were deprecated so maybe github have changed thing again in late 2021? In any case, thanks again.
All worked. Thank you
Solved my problem instantly.
How do I avoid having to type this god awful token password for every single push?
Thanks, it works
Great and useful!
BLESS YOU! Lots of articles are out there on why this was done. This was the first one I found that told you what to do now. Oh, bless you!!!!!!!!!
Thank you! I was stuck but this worked!
git push https://GITHUB_ACCESS_TOKEN@github.com/GITHUB_USERNAME/REPOSITORY_NAME.git
Please edit it like so
I tested it and both work fine. Let me know if you have a specific reason for your solution? Thanks
The only solution that worked for me was:
This is close but not correct if the repo owner is an organization (or some entity other than GITHUB_USERNAME). In that case, the second instance of GITHUB_USERNAME should be the organization name.
thanks a lot 🙂
Thank you very mucha; you are the best. I had waste a lot time searching something like this very helpfull article.
It’s work…thanks a lot
Thanks a lot it worked!
Finally found some advice that worked.
my coworker was too stupid to push to our repo but with my help and this article he finaly made it after 45 mins 🙂 thank you
Thanks for your feedback.
It worked flawlessly. I was banging my head here and there for a day… Thank You Very Much.
Crazy that I had to go this far to find this simple guide
Finally found a perfect solution after pulling my hair for many days!! Thank you!!!
The most helpful article without unnecessary info, thx !
Thanks Ramya Santhosh for this article
Very simple, thank you!
This does not work.
I have generated Personal token with full access. It still looking for aditional token to enter as a password. Something is wrong here.
Thats helpful!! Thanks
Thank you so much, that was very confusing as the command line kept asking for my username and password only to tell me that method has been discontinued.
git push https://@github.com/.git @ 22/09/2021 18:16 is how I managed to push my repository in github. Didin’t work with my username between my token and the repository Thanks a million though, you brought me half way through!!
Nice Content (Simple as Air)
This has solved my issues.
for the first time I have got my solution in only one search.
Thanks very much Ramya Santhosh. This worked beautifully. I also don’t understand why Github didn’t explain this in alerts, as my immediate concern was being able to push like before. Good point noted above that if pushing to someone else’s account one would have to enter their account instead of the account of the person pushing.
My inexpert suspicion is that some of the “account security” features Microsoft is making me set up are good for Microsoft and might be desirable for some users but aren’t necessarily things I want or need.
it is working
Thanks so very much for this Ramya.
The words “enter it instead of your password” is the golden phrase missing from a lot of material.
I share Vincent Flair’s frustration.
Keep up the good work
Thank you. Clearest and easiest solution I have seen. I don’t know why this is not part of the alerts that github keeps sending out. One potential wrinkle — if pushing to a repository of someone else in the team, the should be of the account under which exists.