Git - Authentication issues

Caching your Personal Access Tokens

Source: Caching your GitHub credentials in Git https://docs.github.com/en/get-started/git-basics/caching-your-github-credentials-in-git

So that you don’t have to enter the Personal Access Token every time you try to do a git operation

Once you’ve authenticated successfully, your credentials are stored on your system and will be used every time you clone an HTTPS URL. Git will not require you to type your credentials in the command line again unless you change your credentials.

git config --global credential.gitHubAccountFiltering "false"

Update password using Windows Credential Manager

If you are using a Windows machine and if you are using https method for connecting to Git, and if you need to updated the password for Git, an easy way would be to use Windows Credential Manager. Control Panel -> Credential Manager -> Windows Credential -> Git and update the password there.

Update password using terminal command

If you need to set the username and password, use this command: git remote set-url origin https://<username>:<password>@github.com/<details-about-the-repository>.git

Special characters in passwords

If there are special characters in your password, do not forget to replace them with their ASCII Encoding Reference.

Look at this for reference: Special characters in proxies

Could not read from repository

git pull

Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. A Permission denied error means that the server rejected your connection.

Resolution 1 : git remote set-url origin https://n0281526@git.forge.lmig.com/scm/uscm-esales/services-policywriting.git

Resolution 2 :

If you generated the keys yourself from your client machine, do not forget to add them to the SSH agent using the command ssh-add. Run ssh-add on the client machine, that will add the SSH key to the agent.

To figure out where your client’s SSH agent is looking for private and public keys, use this command: ssh -vT git@github.com

This will show the list of the directories that your computer’s SSH agent is looking in for public and private keys. If everything looks good with this command, you are pretty much set to push and pull from the remote repositories.

You can change the protocol that your local repository is using to communicate with the remote repository : It can be HTTPS or SSH. The issue with using HTTPS URL is, every time you want to push a change, it might ask you for username and password. With SSH, you don’t have to enter username and password every single time.

Use these commands to switch between the two :

  1. If you want to use HTTPS: git remote set-url origin https://github.com/USERNAME/REPOSITORY.git

    If you got authentication issues with the GIT console you can try your auth this way: https://<username>:<password>@bitbucket.org/<username>/<repo>.git

  2. If you want to use SSH, follow this: SSH keys

    1. And then set the origin url: git remote set-url origin git@github.com:USERNAME/REPOSITORY.git

Links to this note