Git Pull: Change Authentication
After three hours of searching and playing I have found the answer myself. The authentication details are stored in the .git/config
file under the url
setting in the [remote "origin"]
section.
How do I provide a username and password when running git clone git@remote.git?
Based on Michael Scharf's comment:
You can leave out the password so that it won't be logged in your Bash history file:
git clone https://username@github.com/username/repository.git
It will prompt you for your password.
Alternatively, you may use:
git clone https://username:password@github.com/username/repository.git
This way worked for me from a GitHub repository.
How do I update the password for Git?
To fix this on macOS, you can use
git config --global credential.helper osxkeychain
A username and password prompt will appear with your next Git action (pull, clone, push, etc.).
For Windows, it's the same command with a different argument:
git config --global credential.helper wincred
Bitbucket fails to authenticate on git pull
You need to reset the password as shown below.
On macOS:
git config --global credential.helper osxkeychain
On Windows 10/11:
git config --global credential.helper store
After executing this, it prompts you for the user name and password for your repo.
How to enter command with password for git pull?
This is not exactly what you asked for, but for http(s):
- you can put the password in .netrc file (_netrc on windows). From there it would be picked up automatically. It would go to your home folder with 600 permissions.
- you could also just clone the repo with
https://user:pass@domain/repo
but that's not really recommended as it would show your user/pass in a lot of places... - a new option is to use the credential helper. Note that credentials would be stored in clear text in your local config using standard credential helper. credential-helper with wincred can be also used on windows.
Usage examples for credential helper
git config credential.helper store
- stores the credentials indefinitely.git config credential.helper 'cache --timeout=3600'
- stores for 60 minutes
For ssh-based access, you'd use ssh agent that will provide the ssh key when needed. This would require generating keys on your computer, storing the public key on the remote server and adding the private key to relevant keystore.
Git push results in Authentication Failed
If you enabled two-factor authentication in your GitHub account you
won't be able to push via HTTPS using your accounts password. Instead
you need to generate a personal access token. This can be done in the
application settings of your GitHub account. Using this token as your
password should allow you to push to your remote repository via HTTPS.
Use your username as usual.
Creating a personal access token
You may also need to update the origin for your repository if it is set to HTTPS. Do this to switch to SSH:
git remote -v
git remote set-url origin git@github.com:USERNAME/REPONAME.git
How to reset git authentication?
It seems that your credential manager stored wrong authentication and reuses it. Reset it.
git config --system --unset credential.helper
More information:
Remove credentials from Git
GitLab remote: HTTP Basic: Access denied and fatal Authentication
How can I save username and password in Git?
Attention: This method saves the credentials in plaintext on your PC's disk. Everyone on your computer can access it, e.g. malicious NPM modules.
Run
git config --global credential.helper store
then
git pull
provide a username and password and those details will then be remembered later. The credentials are stored in a file on the disk, with the disk permissions of "just user readable/writable" but still in plaintext.
If you want to change the password later
git pull
Will fail, because the password is incorrect, git then removes the offending user+password from the ~/.git-credentials
file, so now re-run
git pull
to provide a new password so it works as earlier.
git clone: Authentication failed for URL
The culprit was russian account password.
Accidentally set up it (wrong keyboard layout).
Everything was working, so didnt bother changing it.
Out of despair changed it now and it worked.
If someone looked up this thread and its not a solution for you - check out comments under the question and steps i described in question, they might be useful to you.
Related Topics
How to Get Started Writing a Compositing Wm
Best Approach to Writing a Generic Installer for a Linux Application
Bash File Is Running Fine in Windows for Testng But It Is Not Working in Linux/Mac
How to Read a .Properties File Which Contains Keys That Have a Period Character Using Shell Script
How to Continue One Thread at a Time When Debugging a Multithreaded Program in Gdb
Which Drivers Are Used by Usb Mouse in Linux Kernel
How to Make R Read My Environmental Variables
Upstart Calling Script (For Inserted Usb-Drive)
Current Linux Kernel Debugging Techniques
How to Write and Execute a Hello World Program in File for R
Spidev Linux Driver on Intel Atom Board
What Happens When You Run a Program
Git Enter Long Passphrase for Every Push