Use personal access tokens not password:
Please note that, Beginning August 13, 2021, github will no longer accept account passwords when authenticating Git operations and will require the use of token-based authentication for all authenticated Git operations on GitHub.com. You may also continue using SSH keys where you prefer.
So for, static configuration of usernames for a given authentication context you have to use (when using github):
https://username:<personal-access-tokens>@repository-url.com
For example, to push to https://github.com/blueray453/window-application-calls , you have to run:
git push https://blueray453:<personal-access-token>@github.com/blueray453/window-application-calls
Please note that, we are using <personal-access-tokens>
and not <password>
For further details on how to create a personal access token, please check the documentation. In summary, what the documentation says is, you have to go to https://github.com/settings/tokens and click on Generate new token (classic)
, there select public_repo
for public repositories, or repo
for private repositories. Then use that key as password.
Why only following three solutions:
github documentation says:
GitHub over HTTPS... Every time you use Git to authenticate with
GitHub, you'll be prompted to enter your credentials to authenticate
with GitHub, unless you cache them with a credential helper.
...
Using SSH ... Every time you use Git to authenticate with GitHub,
you'll be prompted to enter your SSH key passphrase, unless you've
stored the key.
github recommends Connecting over HTTPS. Probably because they want you to use Git Credential Manager. I have not used it, so will leave it for someone who has experience with it.
Here, I will only give Git and SSH solutions. Git's documentation discuss how to avoid inputting the same credentials over and over using gitcredentials.
Solution 1
Use credential helpers to cache password (in memory for a short period of time).
git config --global credential.helper cache
now run:
git push https://username:<personal-access-tokens>@repository-url.com
afterwards, only running git push
will be enough.
Solution 2
Use credential helpers to store password (indefinitely on disk).
git config --global credential.helper 'store --file ~/.my-credentials'
You can find where the credential will be saved (If not set explicitly with --file) in the documentation.
now run:
git push https://username:<personal-access-tokens>@repository-url.com
afterwards, only running git push
will be enough.
In this case the content of ~/.my-credentials
will look like:
https://username:<personal-access-tokens>@repository-url.com
NOTE:
To address the concern that gitcredentials store the credentials completely unencrypted ("as is"), You can always encrypt the file and decrypt it before using.
Solution 3
This is almost a direct copy paste from Generating a new SSH key and adding it to the ssh-agent.
Create the ssh key using ssh-keygen -t ed25519 -C "your_email@example.com"
. If you are using a legacy system that doesn't support the Ed25519 algorithm, use: ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Add the SSH key to your account on GitHub. After you generate an SSH key pair, you must add the public key to https://github.com/settings/ssh/new
If not started, start the ssh-agent in the background using $ eval "$(ssh-agent -s)"
Add your SSH private key to the ssh-agent using $ ssh-add ~/.ssh/id_ed25519
. If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_ed25519 in the command with the name of your private key file.
Test the SSH key: ssh -T git@github.com
Change directory into the local clone of your repository (if you're not already there) and run: git remote set-url origin git@github.com:username/your-repository.git
. Now, git push
hopefully will work.