Use Multiple GitHub Accounts on Same Machine
A quick and dirty way
git clone:
sh
git clone https://github.com/<REPO_OWNER>/<REPO>.git
Method 1: Execute commands
sh
git config --local user.name COMMITER_NAME
# NOTE: Do not forget the quotes "" around email!
git config --local user.email "COMMITER_EMAIL"
git remote set-url origin https://<COMMITTER_NAME>:<PAT>@github.com/<REPO_OWNER>/<REPO>.git
Method 2: Modify config file
Just modify these settings in .git/config
:
sh
[remote "origin"]
url = https://<COMMITTER_NAME>:<PAT>@github.com/<REPO_OWNER>/<REPO>.git
fetch = +refs/heads/*:refs/remotes/origin/*
...
[user]
name = <COMMITTER_NAME>
email = <COMMITER_EMAIL>
Now we can do some git operations as COMMITER_NAME ...
sh
git add -u
git commit -m "<COMMIT_MESSAGES>"
git push
References
github-action-push-to-another-repository.sh
Create Fine-grained personal access tokens
- https://github.com/settings/tokens?type=beta
- Commonly used Permissions:
- Repository permissions: (Read and write by default)
- Actions, Commit statuses, Contents, Deployments, Discussions, Environments, Issues, Merge queues, Pages, Pull Requests, Secrets, Variables, Webhooks, Workflows
- Account permissions:
- None
- Repository permissions: (Read and write by default)
Guide from GitHub
References
How To Work With Multiple Github Accounts on your PC
SSH and GPG keys - GitHub
Generating a new SSH key and adding it to the ssh-agent - GitHub Docs
command line - ssh-add complains: Could not open a connection to your authentication agent - Unix & Linux Stack Exchange
ssh-add does not need
-K
anymoreStarting ssh-agent on Windows 10 fails: "unable to start ssh-agent service, error :1058" - Stack Overflow
Example
git clone:
sh
git clone git@github.com-hansimov:Hansimov/turtle-trader.git
git clone git@gist.github.com-hansimov:a68809441cbd16290bdf98a9b5004fdb.git
<repo-local-path>\.git\config
:
sh
[core]
...
[remote "origin"]
url = git@github.com-hansimov:Hansimov/turtle-trader.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
[user]
name = Hansimov
email = <email-address>
C:\Users\xxx\.ssh\config
:
sh
Host github.com
Hostname ssh.github.com
Port 443
ProxyCommand connect -H <proxy-server>:<port> %h %p
IdentityFile ~/.ssh/id_rsa_work
Host github.com-hansimov
Hostname ssh.github.com
Port 443
ProxyCommand connect -H <proxy-server>:<port> %h %p
IdentityFile ~/.ssh/id_rsa_hansimov
Host gist.github.com-hansimov
Hostname ssh.github.com
Port 443
ProxyCommand connect -H <proxy-server>:<port> %h %p
IdentityFile ~/.ssh/id_rsa_hansimov