How can I "login" to git?

149,437

Solution 1

You don't login to Git.

You do login to a Git repository hosting server, which request an authentication, but Git itself has no authentication nor authorization.

What Git does have is credential caching (check the output of git config credential helper).
On Mac: "Updating credentials from the OSX Keychain": you can check if your old user was stored there, and update it.

If you really want to disable the credential helper, you will be asked your credentials every time you push to a repository hosted on a server requesting authentication.

Solution 2

I had a similar problem with Windows. Updating Credentials Manager helped in my case.

To open Credentials Manager search that setting or navigate to: Control Panel\All Control Panel Items\Credential Manager. In Windows Credentials -> Generic Credentials find your repo and update username/password or delete all that are not needed.

Share:
149,437
Admin
Author by

Admin

Updated on October 27, 2021

Comments

  • Admin
    Admin over 2 years

    I need to change who git thinks I am so I can push to a different repo ( both are mine. ).

    Here is a similar issue but I don't want to set any config variables.

    I just want to login once to my current username. I plan on deleting my other account.

    Here is the error when I attempt a git push origin master

    remote: Permission to current_user/fav-front.git denied to user_to_delete. fatal: unable to access 'https://github.com/current_user/repo.git/': The requested URL returned error: 403

    Please note that the git config variables for user and email ( user.name and user.email ) are not related to the authentication that git push uses.

    They are used for commits.

    To reiterate, I want to login to git as current user.

    • dan1st
      dan1st almost 5 years
      What about this answer to the question: stackoverflow.com/a/46337214/10871900 You don't need to include the password: https://[email protected]/username/repo.git
    • Admin
      Admin almost 5 years
      Nope. I saw that. I simply want to login to git like I did with the old account. After this single login git will remember that username / password and I won't have to fiddle with it any more.
    • dan1st
      dan1st almost 5 years
      If you want to do it only once, you can do git push https://[email protected]/username/repo.git master
    • Admin
      Admin almost 5 years
      I want git to think/know that I am user_new and not user_old.
    • dan1st
      dan1st almost 5 years
      Do you want git to think that only for one push or one commit or forever(in that repo)?
    • Admin
      Admin almost 5 years
      I had to login through bash before as it prompted me to ... is this impossible to ever do again or something?
    • dan1st
      dan1st almost 5 years
      Do you mean that git saved your credentials and you want to undo it?
    • Admin
      Admin almost 5 years
      Commits are not even involved as they are local operations. I want git to think this for all my pushes as I mentioned I am deleting my older account.
    • Admin
      Admin almost 5 years
      That appears to be what happened but I'm not sure.
    • dan1st
      dan1st almost 5 years
      What is your credential helper?
    • Admin
      Admin almost 5 years
      I feel like I'm asking how to build a spaceship. I just want to login to git. Git must be black magic as I have seen no Google hit on how to do something like git login
    • Admin
      Admin almost 5 years
      I don't know what that is. I never installed a credential helper.
    • Admin
      Admin almost 5 years
      I'm not using SSH ... I'm using https ... how the fuck does git know who I am. Who stored my credentials is a good question.
    • Admin
      Admin almost 5 years
    • Admin
      Admin almost 5 years
      I never did this unless a monkey got on my machine and did it for me when I wasn't looking.
    • Admin
      Admin almost 5 years
    • Admin
      Admin almost 5 years
      The keychain app has my username and password. That should be illegal. I never gave it permission or set it up.
    • Admin
      Admin almost 5 years
      What is a config?
    • dan1st
      dan1st almost 5 years
      I had internet problems and I didn't see a few comments. It was about finding out that with keychain.
    • dan1st
      dan1st almost 5 years
      And configs are configurations for git(for your repository, your user or your pc)
  • Admin
    Admin almost 5 years
    How did keychain get my permission to save my username and password?
  • VonC
    VonC almost 5 years
    @DaraKhosrowshahi It prompted for them once, then cache them there.
  • Admin
    Admin almost 5 years
    I know but it never asked me. It, git, prompted for them once cached them and locked it down like a f****** rabbit hole and stole 2 hours of my life.
  • dan1st
    dan1st almost 5 years
    This is the credential input from keychain and not from git.
  • Admin
    Admin almost 5 years
    @VonC - I just deleted it from the keychain. This prompted git to ask for username and password.
  • Admin
    Admin almost 5 years
    After re logging in, it put it back in the keychain as the correct user. Is this default behavior for the keychain app?
  • VonC
    VonC almost 5 years
    @dan1st Right, I have deleted the comment
  • VonC
    VonC almost 5 years
    @DaraKhosrowshahi Yes, because of git config credential.helper: it is Git which does instruct the keychain to store your credentials, not the keychain itself.
  • Admin
    Admin almost 5 years
    Well I never touched this thing ... I need to read the docs on git config credential.helper ... I have been traumatized by the keychain app. I am going to sue Apple for emotional distress :)
  • Admin
    Admin almost 5 years
    Trick is to just delete the entry and this will force it to ask you to login again. What I want to know, IS THIS DEFAULT BEHAVIOR?
  • VonC
    VonC almost 5 years
    @DaraKhosrowshahi It is the default behavior to ask (Git or not: if the remote URL demans an authentication, it will ask for it), but the storing part is the result of the credential helper. You can disable it with git config --global --unset credential.helper
  • Admin
    Admin almost 5 years
    So the credential helper, in this case, keychain, is set to this behavior by default?
  • VonC
    VonC almost 5 years
    @DaraKhosrowshahi the keychain is set to this behavior by Git. The keychain alone would not register anything unless explicitly instructed to do so. Here, Git instructs the keychain to do so because of the credential.helper settings.
  • Admin
    Admin almost 5 years
    Yea, I know, I got that, a while back. But what is the default setting for git, is it set to do this by default if I say do a fresh git install ( all default behavior ). Will test tomorrow unless you know.
  • VonC
    VonC almost 5 years
    @DaraKhosrowshahi it should not be set by default, but the result of a manual configuration: help.github.com/en/articles/caching-your-github-password-in-‌​git
  • Admin
    Admin almost 5 years
    I find it a bit creepy that it does this be default, kind of like a web app remembering you logged in with out asking. Guess that is the standard now. There used to be "remember login" box you checked when logging in but not any more.
  • VonC
    VonC almost 5 years
    @DaraKhosrowshahi I am not sure about the "default" part, as I believe you still need to configure Git to trigger that credential caching. But yes, that can be unsettling.