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
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.
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 Core. But Git Credential Manager Core runs on Windows and macOS. Linux support is (up to the point in time of posting) in an early preview.
So, 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
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.
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. I think following the link will be better than reading from here. Anyways, I will copy-paste the commands here.
Create the ssh key using ssh-keygen -t ed25519 -C "your_email@example.com"
. You can also use RSA instead of Ed25519 using ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Add the SSH key to your account on GitHub.
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.