I made all permission reserved personal access token on github.
I saw that
git clone https://<username>:<personal_access_token>@github.com/<username>/<project_name>.git
works.
So How can I clone, commit, and push using personal access tokens?
Like this
cd /tmp
git clone https://<username>:<personal_access_token>@github.com/<username>/<project_name>.git
cd /tmp/auto_tutorial
git commit --allow-empty -m 'Trigger notification'
git push https://<username>:<personal_access_token>@github.com/<username>/<project_name>.git master
Login to your GitHub and go and setup a "Personal Access Token" at https://github.com/settings/tokens
After you have your personal access token, go to terminal and change your "origin" url as below
git remote set-url origin https://[email protected]/REPLACE-WITH-USERNAME/REPLACE-REPO-NAME.git/
If it is your first time starting your repo and haven't pushed before, then add your initial origin as below
git remote add origin https://[email protected]/REPLACE-WITH-USERNAME/REPLACE-REPO-NAME.git/
While it is possible to use the personal access token in the URL like that, it's discouraged because (a) it stores your token in plaintext where it can be read and printed and (b) because it means you have to enter it for each repository.
It's better to use a credential manager to store your credentials by setting credential.helper
to an appropriate value for your platform, and then entering your username when prompted and your token as the password. That will save your credentials for future use across all your projects. If you need to use multiple accounts, just use your username (but not your token) in the URL, and the credential manager will handle that.
The default credential managers you want to use on most platforms are manager
or wincred
on Windows, osxkeychain
on macOS, and libsecret
on Linux. You can also use store
to store in a file on your local disk, which is available on all platforms, but less secure.
Once you've cloned the repository, you can just push with git push origin master
, since the URL you've cloned from will be set to the remote origin
.
Replace the password with your personal access token
Save the changes
Try git commit or git push, it should be working now!
Just push using your remote's name
i.e.: git push origin master
You can use git remote -v
to check current remotes list.
When you clone using an address with personal access token, it gets added to this list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With