Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 902
Paul Avatar asked Sep 01 '26 00:09

Paul


1 Answers

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/*
like image 75
slebetman Avatar answered Sep 02 '26 13:09

slebetman