Paul
Paul

Reputation: 4428

Github mac git use more than one account

I have two accounts on Github, each with a specific use.

I would like to make sure that every time I push my name and password, I can do uploud with the right account.

But it doesn't happen, I use the https connection for this instead of the ssh.

Now going on the keychain, I saw that there are two keys found. One key for userA and one key for userB, both for Github.

Can you give me a hand?

Upvotes: 3

Views: 2501

Answers (2)

slebetman
slebetman

Reputation: 113896

Get yourself a personal access token as described in https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token

Once you have a personal access token you can use it as a password for your account. So you get one for each account.

To use your personal access token add your github account name and use the token as password to the http URL using the username:passowrd@ syntax. For example if you want to clone my httpstress repo you can do:

git clone https://YOUR_GITUB_ACCOUNT:[email protected]/slebetman/httpstress.git

If you have already cloned your repo you can edit your .git/config file and edit your github URL to include your account name and personal access token. Find the following section in your .git/config file:

[remote "origin"]
    url = https://github.com/slebetman/httpstress.git
    fetch = +refs/heads/*:refs/remotes/origin/*

And change it as follows:

[remote "origin"]
    url = https://YOUR_GITUB_ACCOUNT:[email protected]/slebetman/httpstress.git
    fetch = +refs/heads/*:refs/remotes/origin/*

Upvotes: 5

bk2204
bk2204

Reputation: 76499

This information is documented in the Git FAQ. There's an explanation of how to do this with HTTPS and how to do it with SSH.

If you have a recent version of Git, you can read the FAQ by running man gitfaq.

Upvotes: -1

Related Questions