Git keeps prompting me for a password
Asked Answered
D

33

835

I've been using Git for a while now, but the constant requests for a password are starting to drive me up the wall.

I'm using Mac OS X and GitHub, and I set up Git and my SSH keys as instructed by GitHub's Set Up Git page.

I've also added the github SSH key to my Mac OS X keychain, as mentioned on GitHub's SSH key passphrases page. My public key is registered with Git.

Nevertheless, every time I try to Git pull, I have to enter my username and password. Is there something other than an SSH key that I need to set up for this?

Doublefaced answered 14/10, 2011 at 20:24 Comment(11)
Silly question, but have you verified that the SSH key works when simply using ssh to the machine with git?Thrave
You mean something like ssh -T [email protected] ? Yeah, that works just fine (if a little slow).Doublefaced
See also Git push requires username and password.Strobe
For https url, you can use (with git1.8.3+) a git credential helper 'netrc'. See a full example here.Antimicrobial
I am a Windows user, and I was also facing password request issue even after adding my public key to authorized_keys file of server. What really the problem was that I was not keeping my public/private keys under .ssh folder of c:\program files\git folder. If anyone is facing such issue, please copy your keys in this folder and try pushing/pulling.Framing
Set the remote url value in the .git/config file of the repository to [email protected]:{username}/{repo}.git where you replace with your own username and the repo name, obviously. The selected answer is flat-out incorrect.Bubo
What helped me: ssh -Tv [email protected] (replacing example.com with your GitLab domain) Try to push your changes. If it still doesn't work try this: git remote rm origin; git remote add origin git@git.<domain>:<username>/<ProjectName>.git; git push -u origin --all; git push -u origin --tags; If it still doesn't work, try to re add the private key in the website. Last thing to try, add the key from bash: ssh-add id_rsaPillow
You might need to configure your computer with a SSH key and you won't need to constantly submit your password every-time you push the code.Wickiup
for people having trouble cloning with an ssh key, make sure you use the ssh clone url as wellForbid
git config --global credential.helper cacheSuperfine
Other possibly related Questions: Git keeps prompting me for a password and Configuring Git over SSH to login once. Cross site: How to make git not prompt for passphrase for ssh key? (on superuser) and git with ssh keeps asking for passphrase everytime (on U&L)Herriot
M
937

I think you may have the wrong Git repository URL.

Open .git/config and find the [remote "origin"] section. Make sure you're using the SSH one:

ssh://[email protected]/username/repo.git

You can see the SSH URL in the main page of your repository if you click Clone or download and choose ssh.

And NOT the https or git one:

https://github.com/username/repo.git
git://github.com/username/repo.git

You can now validate with just the SSH key instead of the username and password.

If Git complains that 'origin' has already been added, open the .config file and edit the url = "..." part after [remote origin] as url = ssh://github/username/repo.git


The same goes for other services. Make sure the address looks like: protocol://something@url

E.g. .git/config for Azure DevOps:

[remote "origin"]
    url = https://[email protected]/mystore/myproject/
    fetch = +refs/heads/*:refs/remotes/origin/*
Mourner answered 14/10, 2011 at 21:10 Comment(13)
This may be it. When I call git remote -v I get: origin github.com/Foo/Bar.git (fetch) origin github.com/Foo/Bar.git (push) whereas to work with SSH it seems that it should be: origin [email protected]:Foo/Bar.git (fetch) origin [email protected]:Foo/Bar.git (push) This may be because I originally checked out my project using GitHub's Mac application (mac.github.com). Any idea how I can fix it?Doublefaced
Either fix the url in the .git/config file, use git-remote to fix it, or delete your local repo and clone it again with the correct URL.Mourner
Just to spell this out (as I needed it): open .git/config and in the [remote "origin"] section set url = ssh://[email protected]/username/Repo.git. That worked for me.Apuleius
Odd, @GregK's solution didn't work for me, but url = [email protected]:organization/Repo.git did work. +1 for leading me down the right path though! Success!Fetich
I'm curious why you describe the https url as the "wrong" one, when the git documentation describes it as the recommended method: help.github.com/articles/generating-ssh-keys ? Don't get me wrong, I prefer SSH connection myself, but there seems to be a disparity in recommendations.Uremia
I can't stress enough how important it is to CLONE using ssh://git@github/[username]/[reponame].git is you want to use an key to access GIT not have to type your username and password each time. I found the only way to fix it was to remove the local repo and clone again $ git clone ssh://git@github/[username]/[reponame].gitBloodmobile
@GeneM. I'm pretty sure you can simply change the origin url of your clone in .git/gitrc to avoid re-cloning.Mourner
https URLs work just fine in MacOSX if you use @orkoden's osxkeychain solutionCentrifuge
Editing .git/config directly is not recommended when there is a git command for doing the same thing: git remote set-url origin [email protected]:account/repository. The reason is you may accidentally corrupt the contents of .git/config.Poaceous
Just adding that this worked for me, but I did NOT include the ssh:// prefix to the ssh github url. That is, I simply set the url to [email protected]:username/repo.gitWorkingwoman
Remote url should be [email protected]:username/repo.git - not this nonsense.Bubo
Permission denied (publickey). fatal: Could not read from remote repository. Trimolecular
This got me past 1 hurdle, at least git is now using my ssh key, but it still keeps prompting for the public key passphrase on each git operationConsol
Z
663

Configuring credential.helper

On OS X (now macOS), run this in Terminal:

git config --global credential.helper osxkeychain

It enables Git to use file Keychain.app to store username and password and to retrieve the passphrase to your private SSH key from the keychain.

For Windows use:

git config --global credential.helper wincred

For Linux use:

git config --global credential.helper cache // If you want to cache the credentials for some time (default 15 minutes)

OR

git config --global credential.helper store // if you want to store the credentials for ever (considered unsafe)

Note: The first method will cache the credentials in memory, whereas the second will store them in ~/.git-credentials in plain text format.

Check here for more info about Linux method.
Check here for more info about all three.

Troubleshooting

If the Git credential helper is configured correctly macOS saves the passphrase in the keychain. Sometimes the connection between SSH and the passphrases stored in the keychain can break. Run ssh-add -K or ssh-add ~/.ssh/id_rsa to add the key to keychain again.

macOS v10.12 (Sierra) changes to ssh

For macOS v10.12 (Sierra), ssh-add -K needs to be run after every reboot. To avoid this, create ~/.ssh/config with this content.

Host *
    AddKeysToAgent yes
    UseKeychain yes
    IdentityFile ~/.ssh/id_rsa

From the ssh_config man page on 10.12.2:

UseKeychain

On macOS, specifies whether the system should search for passphrases in the user's keychain when attempting to use a particular key. When the passphrase is provided by the user, this option also specifies whether the passphrase should be stored into the keychain once it has been verified to be correct. The argument must be 'yes' or 'no'. The default is 'no'.

Apple has added Technote 2449 which explains what happened.

Prior to macOS Sierra, ssh would present a dialog asking for your passphrase and would offer the option to store it into the keychain. This UI was deprecated some time ago and has been removed.

Zuzana answered 11/7, 2012 at 8:44 Comment(17)
This is by far the best way to do this since the Github application for OSX (maybe Windows as well) uses the https path for git repos by default. There is also a good reason for using https rather than ssh/git since many corporate networks only allow traffic on port 80 and 443 for security reasons.Prochora
You need git 1.7.10 or newer to use the credential helper.Malposition
+1 for keychain.app solution. This is GREAT for me because my employer's git server only supports http served via apache and they strongly discourage using the .netrc file method which puts your password in plaintext.Tugman
Note, I got the error 'credential-osxkeychain' is not a git command. as I didn't have the credential helper installed. I followed the instructions here to install it: help.github.com/articles/set-up-git#password-cachingSwedenborgianism
Yes you need to install git with the credential helper. Depending on how you install it (homebrew, macports, source, etc.) you might need to pass some compile flags. For macports, install it with port install git-core +credential_osxkeychainZuzana
For windows use: git config --global credential.helper wincredMonteverdi
Is it still using the git ssh key? I want to make sure I am not bypassing the security and using a less secure the username and password method.Wallop
Yes it is. The password you save in Keychain.app is the one that unlocks the private SSH key on your machine. Your username and password for the git server you use should be different.Zuzana
Error : git: 'credential-osxkeychain' is not a git command. See 'git --help'.Heteromerous
Thanks for the Sierra update, I just updated and couldn't figure out why github kept asking for pw when I added the git config --global credential.helper osxkeychain The config file in my .ssh directory fixed me up.Lighter
Mac Sierra 10.2 was the reason this keeps prompting me. ssh-add -K doing this fixed the problem and added the missing Identity File back to mac.Arginine
I've been pulling my hair out over the Sierra change. Modifying ~/.ssh/config did the trick!Intisar
Great solution. Though note, you don't even need the Host * bit, if you put the rest at the top-level.Mut
@AndreyLuiz Hey do you know how to do it in linux?Personal
This answer must be marked as correct one. Came here after installing Sierra, and ssh-add -K together with creating .ssh/config file did the trick.Menke
For Linux use git config --global credential.helper cacheWhithersoever
I have configured credential.helper and it worked for a while. But after 3 months the git fetch started to ask for credentials again. I looked into keychain and the credentials exist just fine. I entered the same credentials again for the git fetch command and new item was created in keychain, with same credentials. Do not know why.Cristencristi
S
162

This happened to me when I upgraded to macOS v10.12 (Sierra). Looks like the SSH agent got cleared upon upgrade.

$ ssh-add -L
The agent has no identities.

Simply running ssh-add located my existing identity. I entered the password and was good to go again.

Serving answered 21/9, 2016 at 12:17 Comment(9)
+1 broken by Sierra upgrade. Note the password is the password for your SSH key and not your Mac user password.Publicness
Doing ssh-add does work but appears to be reset by closing the Terminal window. Maybe this is a new "feature".Oster
Heads up - this happened again with another Sierra update (10.12.2) but the same fix applies.Molarity
Does anyone know how to have this not be reset after Terminal is closed?Stockbroker
Nevermind, found a solution for the issue where this is reset after Terminal is closed: apple.stackexchange.com/a/264974Stockbroker
got same message but my box broke after updating OSX over last weekend.Admission
This also worked for me after upgrading macOS SierraLandtag
I had just updated my macbook pro to 10.12.2 and it broke my git. Using ssh-add totally worked for me. Thanks @amcc!Dunlavy
this worked after switching from Xfce to KDE for some reasonFou
C
77

As others have said, you can install a password cache helper. I mostly just wanted to post the link for other platforms, and not just Mac. I'm running a Linux server and this was helpful: Caching your GitHub password in Git

For Mac:

git credential-osxkeychain

Windows:

git config --global credential.helper wincred

Linux:

git config --global credential.helper cache
git config --global credential.helper 'cache --timeout=3600'
# Set the cache to timeout after 1 hour (setting is in seconds)
Copperplate answered 12/2, 2015 at 20:42 Comment(1)
I had to scroll down to the third answer to see the Linux instructions, these should be in the primary answer since it is a commonly referenced issue.Introvert
R
74

Use this: Replace github.com with the appropriate hostname

git remote set-url origin [email protected]:user/repo.git
Raimes answered 22/2, 2013 at 22:48 Comment(4)
I already have that set when viewing git remote -v. Yet, I am still being prompted for password.Epiclesis
Same, I have set as what he suggested, but I still get prompt for password, how do I prevent that ?Heteromerous
@Epiclesis : Did you ever found a solution for you ?Heteromerous
This works properly. This is weird that remote URL with git@** doesn't prompt credentials and URL with https@** does :). Thus I found this doc.Saidee
F
29

Also look for who is asking you for the passphrase. Is it Git or your SSH agent?

In my case, every time I did git pull it was asking me:

Enter passphrase for key '/work/username/.ssh/id_rsa':

So I assumed it was Git asking for a passphrase. So I kept hunting for solutions, only to realize later that my SSH agent had shut down. Which can be fixed using eval $(ssh-agent) and ssh-add as given here.

Also am pasting below a little snippet you can add to your ~/.bashrc file (or the equivalent) to ensure that your SSH agent is started on your login.

In any case this was a pretty silly mistake I made, but posting it here, just in case it helps someone save some time from barking up the wrong tree, like I did.

SSH_ENV="$HOME/.ssh/environment"

# Start the ssh-agent
function start_agent {
    echo "Initializing new SSH agent..."

    # Spawn ssh-agent
    /usr/bin/ssh-agent | sed 's/^echo/#echo/' > ${SSH_ENV}
    echo succeeded
    chmod 600 ${SSH_ENV}
    . ${SSH_ENV} > /dev/null
    /usr/bin/ssh-add
}

if [ -f "${SSH_ENV}" ]; then
     . ${SSH_ENV} > /dev/null
     ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
        start_agent;
    }
else
    start_agent;
fi

Fleisher answered 23/8, 2017 at 2:48 Comment(1)
Pretty sure you are missing a line in the code above - as per https://mcmap.net/q/12877/-start-ssh-agent-on-login-closed you need to have SSH_ENV="$HOME/.ssh/environment"Eldwon
B
23
git config credential.helper store

Note: While this is convenient, Git will store your credentials in clear text in a local file (.git-credentials) under your project directory (see below for the "home" directory). If you don't like this, delete this file and switch to using the cache option.

If you want Git to resume to asking you for credentials every time it needs to connect to the remote repository, you can run this command:

git config --unset credential.helper

To store the passwords in .git-credentials in your %HOME% directory as opposed to the project directory: use the --global flag

git config --global credential.helper store
Biisk answered 13/6, 2017 at 7:53 Comment(0)
V
12

In Windows for Git 1.7.9+, run the following command on the command prompt to open the configuration file in a text editor:

git config --global --edit

Then in the file, add the following block if not present or edit it accordingly:

[credential "https://giturl.com"]
username = <user id>
helper = wincred

Save and close the file. You will need to provide the credentials only once after the above change.

Vested answered 13/4, 2015 at 1:32 Comment(2)
this works perfect, you saved my hours, now I can concentrate on my work, Thanks a lot Brother.Meaning
This did not work for me. "error: There was a problem with the editor '"D:/Programs/GitExtensions/GitExtensions.exe" fileeditor'"Consol
G
11

Use the following command to increase the timeout period so that you could retype password for a while

git config --global credential.helper 'cache --timeout 3600'

I used it for Bitbucket and GitHub it works for both. The only thing you need to do is 3600 is in seconds. Increase it to whatever extent you want. I changed it to 259200 which is about 30 days. This way I re-enter my password for every 30 days or so.

Generic answered 23/9, 2017 at 9:18 Comment(3)
Ok, I've found that this does not persist after a restart, so you still need to enter the password after a restart, regardless of timeout...Psilocybin
This is a nice way to make in cache :) At least saved my time. ThanksMargravine
@BenWinding because it stores credentials in memory.Schulein
D
10

Guide to Git on Windows and GitHub using SSH to push/pull: An Illustrated Guide to Git on Windows

  1. Download and install PuTTY
  2. Set environment variable 'GIT_SSH' = 'path\to\plink.exe' (in installed putty folder) - very important!!!
  3. Restart Windows Explorer for environment variables to take effect (cannot only restart command prompt)
  4. Run puttygen.exe to generate new key, copy the public key to the GitHub site
  5. Save this new private key somewhere safe on the disk (preferable not Dropbox)
  6. Run putty.exe and connect SSH to github.co
  7. Quickly get to startup folder by running "shell:startup".
  8. Make your private key startup with Windows via pageant. Create a shortcut in Startup folder with syntax "path\to\pageant.exe" "path\to\privatekey"
  9. We do not need to set the 'puttykeyfile' setting inside .git/config of our repositories
  10. Very important is that the "SSH clone URL" of GitHub is used and not HTTPS.
Dunaway answered 29/10, 2013 at 15:7 Comment(1)
Nobody should be using putty anymore. You can do everything now with built in Windows 10 utilities. Let putty, just be putty.Caskey
O
9

On Windows Subsystem for Linux (WSL) this was the only solution that I found to work:

eval `ssh-agent`; ssh-add ~/.ssh/id_rsa

It was a problem with the ssh-agent not being properly registered in WSL.

Oni answered 17/11, 2019 at 14:50 Comment(1)
Been a whlie, but this is what fixed my issue.Plane
L
8

If you want to stop Git from always asking you for the login credentials of your GitHub repository this can be easily done.

Using SSH instead of HTTPS

You can update the origin remote using SSH instead of HTTPS"

git remote set-url origin [email protected]:username/your-repo.git

Configure Git to Store your Password and Username

Here’s how you can make Git store the username and password:

git config --global credential.helper store

Next, save the username and password for a session:

git config --global credential.helper cache
Lys answered 11/2, 2020 at 3:0 Comment(0)
M
8

Git will prompt you for a password if you are using the https protocol. If you use ssh, it will do the authentication using your private key instead of asking for password.

Here is how to fix this:

git remote -v

This will show the url for origin. And you will notice https in this url. (Example here)

Now, you will have to just remove this first and add the url with ssh

git remote remove origin

git remote add origin [email protected]:PrestaShop/PrestaShop.git
Minni answered 30/6, 2020 at 10:7 Comment(1)
After removing and adding the remote repo, if you're unable to push your local branch to GitHub, the below command should help. ``` xpetta@host:~/home/xpetta$ git push fatal: The current branch ABC-123 has no upstream branch. To push the current branch and set the remote as upstream, use git push --set-upstream origin ABC-123 ```Citrin
S
7

I feel like the answer provided by static_rtti is hacky in some sense. I don't know if this was available earlier, but Git tools now provide credential storage.

Cache Mode

$ git config --global credential.helper cache

Use the “cache” mode to keep credentials in memory for a certain period of time. None of the passwords are ever stored on disk, and they are purged from the cache after 15 minutes.

Store Mode

$ git config --global credential.helper 'store --file ~/.my-credentials'

Use the “store” mode to save the credentials to a plain-text file on disk, and they never expire.

I personally used the store mode. I deleted my repository, cloned it, and then had to enter my credentials once.

Reference: 7.14 Git Tools - Credential Storage

Supertanker answered 15/8, 2018 at 2:31 Comment(3)
For Windows credential.helper cache does NOT work. It should be git config --global credential.helper wincred.Idonna
Storing it worked and now it allows me to commit my changes without prompting for a password all the time, you're a lifesaver!Holloway
In Linux this did the job for me git config --local credential.helper store. In my case, I'm over HTTPS, in this way I only type username/password one time and after that, my credentials are reused from ~/.git-credentialsTormentil
D
6

If Git prompts you for a username and password every time you try to interact with GitHub, you're probably using the HTTPS clone URL for your repository.

Using an HTTPS remote URL has some advantages: it's easier to set up than SSH, and usually works through strict firewalls and proxies. However, it also prompts you to enter your GitHub credentials every time you pull or push a repository.

You can configure Git to store your password for you. For Windows:

git config --global credential.helper wincred
Deaver answered 13/9, 2018 at 3:2 Comment(0)
P
5

I figure you fixed your problem, but I don't see the solution here that helped me, so here it is.

Type in terminal:

echo "" > ~/.ssh/known_hosts

That will empty your known_hosts file, and you'll have to add every host you used and have connected to, but it solved the problem.

Pompei answered 1/8, 2012 at 7:18 Comment(6)
cat /dev/null > ~/.ssh/known_hosts will do the same.Arbuthnot
> ~/.ssh/known_hosts is even shorter :)Sac
rm ~/.ssh/known_hosts should do the job too. I would advise against this though.Zuzana
If you need to remove a host from ~/.ssh/known_hosts, there is a less impactful way than wiping out the file. ~/.ssh/known_hosts is just a text file and if you can find the offending hosts in the file, you can just delete their lines. You may want to back up the file before editing it. If you only have a few entries in the file, then wiping it out might not be a bad idea. I work on lots of servers so my ~/.ssh/known_hosts has hundreds of entries in it and I'm not quite ready to delete them all to remove a few entries.Bourassa
@Pompei This does not prevent git from asking me for my password!Epiclesis
Try that, still prompt for password ... :(Heteromerous
G
5

I had the same problem. MacOS Mojave keychain keeps asking for the passphrase. Your id_rsa should be encrypted with a passphrase for security. Then try adding it to the keychain ssh-add -K ~/.ssh/id_rsa

If your key is in another folder than ~/.ssh then substitute with the correct folder.

Keychain now knows your ssh key, hopefully, all works now.

If you are still facing the issue then try

1. brew install keychain

2. echo '/usr/local/bin/keychain $HOME/.ssh/id_rsa' >> ~/.bash_profile
   echo 'source $HOME/.keychain/$HOSTNAME-sh' ~/.bash_profile

3. ssh-add -K ~/.ssh/id_rsa

Hopefully, it should work now.

Update: The -K flag has since been deprecated. Use the following instead:

ssh-add --apple-use-keychain ~/.ssh/id_ed25519 # path to private key
Gliadin answered 25/6, 2020 at 2:36 Comment(2)
Thank you! The top solution didn't work for me but using ssh-add like you said finally resolved the issue for me.Confirm
Since the "-K" flag is deprecated use "--apple-use-keychain" instead: ssh-add --apple-use-keychain ~/.ssh/id_rsaKainite
B
4

Running macOS Cataline 10.15, the keychain caching method was not working for me. And I wanted to use https:// not ssh

Here is what worked for me:

git remote rm origin

git remote add origin https://your_git_username:[email protected]/path_to_your_git.git

This should work on GitLab too

Make sure if the username contains an email address, to remove the @email part or you'll get an error stating URL using bad/illegal format or missing URL.

Hope this helps!

Bin answered 7/4, 2020 at 16:49 Comment(1)
This is the ONLY solution that worked for me. your_git_username was critical. It was actually not necessary to put :your_git_password. At this point, even though it still asked for a "passphrase", it would now accept the account password.Feria
C
4

Here is the solution to this issue:

git remote -v

This will display the URL for origin. If it starts with https, we need to remove this URL and replace with URL for ssh

git remote remove origin
git remote add origin [email protected]:PrestaShop/PrestaShop.git

After you have removed and added the remote repository again, if you're still unable to push your local branch to GitHub, then the command listed below should help to resolve this issue.

xpetta@host:~/home/xpetta$ git push
fatal: The current branch ABC-123 has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin ABC-123

Alternatively you can open the .git/config and find the [remote "origin"] section and make sure the URL which is being used doesn't begins with https if it begins with https replace it with the ssh URL from the remote GitHub repo. Same applies to other services listed within .git/config such as fetch and likewise, need to be replace with the ssh URL.

Citrin answered 3/5, 2023 at 23:25 Comment(0)
I
3

orkoden's answer on using the keychain with Git in your terminal was incomplete and raises errors. This is what you have to do to save the username and password you enter in the the terminal in your keychain:

curl http://github-media-downloads.s3.amazonaws.com/osx/git-credential-osxkeychain -o git-credential-osxkeychain
sudo mv git-credential-osxkeychain /usr/local/bin
sudo chmod u+x /usr/local/bin/git-credential-osxkeychain

Then enter

git config --global credential.helper osxkeychain

If you have already done the part with Git configuration before the curl stuff, it's no problem; it'll work.

Isadoraisadore answered 1/11, 2013 at 18:21 Comment(1)
What if I'm on linux.Epiclesis
L
3

As static_rtti said above, change

https://github.com/username/repo.git
git://github.com/username/repo.git

to

ssh://[email protected]/username/repo.git

I myself changed the https in the .git/config file to ssh, but it still wasn't working. Then I saw that you must change github.com to [email protected]. A good way to get the actual correct URL is to go to your project page and click this:

Change HTTPS to SSH to get the right URL

Then add this URL to the configuration file.

Layer answered 20/1, 2016 at 3:0 Comment(2)
I have that in my config config file already what else should I check ?Heteromerous
Did you change it on github.com as well?Layer
B
2

I agree with "codehugger" and using the instruction of "orkoden" it worked for me - on NetBeans 7.3 - when you right-click on the file and select context menu - push - a 'push to remote' window opened - there are two options here:

  1. origin:https://github.com/myaccount/myproject.git/

  2. https://github.com/myaccount/myproject.git/

As you can see, the difference is the origin parameter in the URL - you do not want to choose this option (1) you want to check option (2), and that works just fine for me.

Biagio answered 15/6, 2013 at 2:57 Comment(0)
I
1

There are different kind of authentications depending on your configuration. Here are a few:

  1. git credential-osxkeychain.

    If your credential is invalid, remove it by:

      git credential-osxkeychain erase
    

    or:

      printf "protocol=https\nhost=github.com\n" | git credential-osxkeychain erase
    

    So Git won't ask you for the keychain permission again. Then configure it again.

    See: Updating credentials from the OS X Keychain at GitHub

  2. Your SSH RSA key.

    For this, you need to compare your SSH key with what you've added, check by ssh-add -L/ssh-add -l if you're using the right identity.

  3. Your HTTPS authentication (if you're using https instead of ssh protocol).

    Use ~/.netrc (%HOME%/_netrc on Windows), to provide your credentials, e.g.

      machine stash1.mycompany.com
      login myusername
      password mypassword
    

Learn more: Syncing with GitHub at Stack Overflow.

Ironhanded answered 11/4, 2016 at 9:23 Comment(0)
W
1

Before you can use your key with GitHub, follow this step in the tutorial, Testing your SSH connection:

$ ssh -T [email protected]
# Attempts to ssh to GitHub
Wrestle answered 1/8, 2016 at 14:12 Comment(0)
C
1

If you're using Windows and this has suddenly started happening on out of the blue on GitHub, it's probably due to GitHub's recent disabling support for deprecated cryptographic algorithms on 2018-02-22, in which case the solution is simply to download and install the latest version of either the full Git for Windows or just the Git Credential Manager for Windows.

Chesson answered 16/3, 2018 at 11:6 Comment(0)
S
1

If you have SSH agent set up, you can also add this to your ~/.gitconfig to force git to use SSH for all GitHub repos rather than HTTPS:

[url "ssh://[email protected]/"]
    insteadOf = git://github.com/
    insteadOf = https://github.com/

(If you're mostly working with public repos, you can also use pushInsteadOf rather than insteadOf, as reading from a public repo can be done without authentication).

Sensate answered 30/5, 2020 at 12:3 Comment(0)
I
0

Step 1: check your current configuration

cat .git/config

You will get:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
    precomposeunicode = true
[remote "origin"]
    url = https://github.com/path_to_your_git.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[user]
    name = your_username
    email = your_email
[branch "master-staging"]
    remote = origin
    merge = refs/heads/master-staging

Step 2: remove your remote origin

git remote rm origin

Step 3: add remote origin back with your username and password

git remote add origin https://your_git_username:[email protected]/path_to_your_git.git
Iodic answered 14/9, 2015 at 17:6 Comment(1)
After you've added the remote origin again you also need to align your branches remote and local - something like this: git branch --set-upstream master origin/masterAcus
M
0

Microsoft Stack solution (Windows and Azure DevOps)

First open the .git/config file to make sure the address looks like:

protocol://something@url

E.g. .git/config for Azure DevOps:

[remote "origin"]
    url = https://[email protected]/mystore/myproject/
    fetch = +refs/heads/*:refs/remotes/origin/*

If the problem still persists, open Windows Credential Manager, click on the safebox named Windows Credentials and remove all the git related credentials.

Now the next time you log into git, it won't go away anymore.

Merkle answered 11/2, 2020 at 9:36 Comment(0)
A
0

I had this issue. A repo was requiring me to input credentials every time. All my other repos were not asking for my credentials. They were even set up to track GitLab using HTTPS under the same account credentials, so it was weird that they all worked fine except one.

Comparing the .git/config files, I found that there were 2 key differences in the URLs which was causing the issue:

Does ask for credentials:

https://gitlab.com/myaccount/myproject

Does not ask for credentials:

https://[email protected]/myaccount/myproject.git 

So adding the "myaccount@" and ".git" resolved the issue in my case.

Apheliotropic answered 3/12, 2020 at 20:37 Comment(0)
U
0

In my case, I was always getting a password prompt when I tried to cherrypick a URL like below:

git fetch http://username@gerrit-domainname/repositoryname refs/changes/1/12345/1 && git cherry-pick FETCH_HEAD

This URL worked well when cherrypicked on a different machine. However, At my end when I try to cherrypick with correct password abc@12345 I used to get below error:

remote: Unauthorized
remote: Authentication failed for http://username@gerrit-domainname  

In my git config file the remote URL was like below:

url = ssh://gerrit-domainname:8080/wnc

Solution:
I resolved the authentication failure issue by providing the HTTP Password which I found at
My gerrit account -> Settings -> HTTP Password.

The HTTP Password was something like Th+IsAduMMy+PaSS+WordT+RY+Your+OwNPaSs which was way different than my actual password abc@12345

Note: My URL to cherrpick starts with git fetch ... So, this solution might work on git checkout/download where the URL starts with git fetch ...

Undersecretary answered 13/2, 2021 at 15:24 Comment(0)
P
0

Faced same kind of issue.

Please make sure you have properly set the remote origin:

$git remote add origin master "https://...git " 
Peeler answered 13/9, 2021 at 10:34 Comment(0)
M
0

In windows machine: Install GitHub CLI

choco install gh

Then run the command:

gh auth login

and follow the Instruction

Also you can follow this link:

https://cli.github.com/manual/gh_auth_login

Melquist answered 13/10, 2021 at 8:41 Comment(0)
M
0

I'm sorry but all answers are a long way around to a simple solution. You want to update your netrc file

nano ~/.netrc machine github.com login yourusername password ghp_yourtoken

Miocene answered 18/3 at 21:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.