I am trying to sign in using the Git command line, so that I can push my changes to a repository I have. I usually use a different account to the one I'm trying to use right now, and pushing works fine on there. The terminal is the one integrated into Visual Studio Code, and it is Git Bash.

What I want to do is sign into this different account and then push from that account. I remember at one point there was a popup with a login box on it. How would I get this to show up again?

So far, I have tried using the commands:

git config user.name my-name
git config user.email my-email

Which don't appear to have asked for any credentials. Upon Googling (just now) it appears that they are used just to set my commit username.

So how do I log in from the Git command line? I've been stuck on this for ages and I feel like there's probably a really simple solution.

Any help would be greatly appreciated.

5

3 Answers

user.name & user.email have nothing to do with the server communication - they are used only when committing. If you use HTTP to access your repo, then add another remote with your new username in the URL:

git remote add origin2 

And then push/fetch using the new remote:

git push origin2 branch_name 

Windows will recognize that the URL has new username and will ask for your creds.

You can also use SSH. Generate the key, upload the public one to your Git Server under the right account, set up .ssh/config to use that key. Though you still will need either to add new remote or re-point the existing one to switch to SSH protocol.

Git Credential Manager

Another option (as stated here) that's available since 2018 is to git credential-manager reject <url>. Though personally I didn't test it.

Just entering your user in the command line won't work for newer versions of git. To sign in, you'll need to download git CLI, then do gh auth login

3

Here is the link to the documentation that explains how to login to github using a variety of methods.

If you are using a Mac you may also have to remove any cached credentials.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy