Git push requires username and password

前端 未结 24 2036
灰色年华
灰色年华 2020-11-22 04:14

I cloned a Git repository from my GitHub account to my PC.

I want to work with both my PC and laptop, but with one GitHub account.

When I try to push to or p

相关标签:
24条回答
  • 2020-11-22 04:47

    I just came across the same problem, and the simplest solution I found was to use SSH URL instead of HTTPS one:

    ssh://git@github.com/username/repo.git
    

    And not this:

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

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

    0 讨论(0)
  • 2020-11-22 04:47

    Update for HTTPS:

    GitHub has launched a new program for Windows that stores your credentials when you're using HTTPS:

    To use:

    • Download the program from here

    • Once you run the program, it will edit your .gitconfig file. Recheck if it edited the correct .gitconfig in case you have several of them. If it didn't edit the correct one, add the following to your .gitconfig

      [credential]
          helper = !'C:\\Path\\To\\Your\\Downloaded\\File\\git-credential-winstore.exe'
      

      NOTE the line break after [credential]. It is required.

    • Open up your command line client and try git push origin master once. If it asks you for a password, enter it and you're through. Password saved!

    0 讨论(0)
  • 2020-11-22 04:49
     # gen  the pub and priv keys
     # use "strange" naming convention, because those WILL BE more than 10 ...
     ssh-keygen -t rsa -b 4096 -C "me@corp.com" -f ~/.ssh/id_rsa.me@corp.com@`hostname -s`
    
     # set the git alias ONLY this shell session
     alias git='GIT_SSH_COMMAND="ssh -i ~/.ssh/id_rsa.me@corp.com.`hostname -s`" git'
    
     # who did what when and why
     git log --pretty --format='%h %ai %<(15)%ae ::: %s'
    
     # set the git msg
     export git_msg='issue-123 my important commit msg'
    
     # add all files ( danger !!! ) and commit them with the msg
     git add --all ; git commit -m "$git_msg" --author "Me <me@corp.com"
    
     # finally 
     git push
    
    0 讨论(0)
  • 2020-11-22 04:50

    I had the same issue.

    So I changed the .git/config file from my project,

    url = https://github.com/<your-user-here>/<your-repo-here>
    

    to

    url = git@github.com:<your-user-here>/<your-repo-here>
    

    and added the SSH public key to the Git profile which is in setting.

    For the SSH public key:

    cat ~/.ssh/id_rsa.pub
    
    0 讨论(0)
  • 2020-11-22 04:51

    If you've got 2FA enabled on your Github account, your regular password won't work for this purpose, but you can generate a Personal Access Token and use that in its place instead.

    Visit the Settings -> Developer Settings -> Personal Access Tokens page in GitHub (https://github.com/settings/tokens/new), and generate a new Token with all Repo permissions:

    The page will then display the new token value. Save this value and use it in place of your password when pushing to your repository on GitHub:

    > git push origin develop
    Username for 'https://github.com': <your username>
    Password for 'https://<your username>@github.com': <your personal access token>
    
    0 讨论(0)
  • 2020-11-22 04:52

    As many users has said, you just have to change your Git repository URL from HTTPS to SSH.

    If you haven't generated a SSH key in your machine, then your are going to have to do it.

    Just as an additional information, after doing this change I still was getting the same error:

    Permission Denied.

    In my case, the problem was that I was using the Windows Shell to execute the ngh command; since this command should open a prompt to request the SSH phrase and the Windows Shell doesn't open these kinds of prompts, the authentication just failed.

    So, I just had to open the Git shell and execute the ngh command there, put the SSH phrase in the prompt every time it asked for it and "voilà"... It just worked fine!

    0 讨论(0)
提交回复
热议问题