Thank you for your help.
I used to create a Git account and used it on my private PC for a while, but recently I started using it for work.
This time, I would like to create a separate Git account, create a separate private account, a separate repository, but when I push on my private PC, it is recognized by the user name I created before (currently using for work), and I cannot push it.
Please let me know if anyone knows how to separate Git accounts on the same PC.
Thank you for your cooperation.
git github
It depends on whether you use SSH or HTTPS...
If this problem occurs with HTTPS, I think the credential helper remembers the credentials (username/password).In this case, you can have another credential stored by putting the username in the URL.
git clone https://github.com/user_a/aprojectX
↓
git clone https://[email protected] /user_a/aprojectX
See also
In this case, the user is identified by the private key and must use the private key differently.
Depending on your environment, if you use git push/pull
in the command, you are probably using openssh for SSH connections.Then you can specify a private key for each destination in .ssh/config
.
For example, .ssh/config
should include:
Host github-private
HostName github.com
IdentityFile~/.ssh/id_rsa_private
If you use the github-private
determined above instead of github.com
as the hostname,
git clone [email protected]:user_a/projectX
↓
git clone git @github-private:user_a/projectX
~/.ssh/id_rsa
is used instead of ~/.ssh/id_rsa_private
.
For Github only,
and so on.
See also
You can rewrite the URL you want to clone by hand, or, for example, if you want to apply it to a Github user, you can automatically replace it by generating the entry url.<base>.insteadOf
in gitconfig.You can replace it from the HTTPS URL.
[url"git@github-private:user_a/"]
installOf=https://github.com/user_a/
Note Rewrite Git Repository URL Settings "insteadOf" and "pushInsteadOf"-kakakakukublog
In either way, the name and email at the time of commitment must be changed separately.This is a function called conditional inclusions, and you might want to set it to ~/private/
and below to apply this gitconfig...
Reference Use includeIf to replace git config for each project - kakakaku blog
There is no description of the operating system, but how about dividing the users on the operating system?
As @unarist states, github passes SSH (public) keys registered with github as authentication and then performs authorization logic, causing this problem because of the git protocol. In @unarist's answer, A recent method I do is to set the ~/.ssh/config
provides a way to configure host settings for each key and git clone with that name, which is a little inconvenient because you have to change the host name for each account.
export GIT_SSH_COMMAND='ssh-i~/.ssh/another-account-key'
By enabling this setting only in a specific working directory where you want to use this account, such as using direnv, you can consolidate the repositories that you want to access under that directory and run the git clone in the usual flow.
For your reference, GIT_SSH_COMMAND
is an environment variable that instructs git to replace the internal ssh command with the specified command.
For your information, using the Pro version of GitKraken, it seems that you can switch between multiple accounts.
(GUI Client for Windows, Mac, and Linux)
How can I use multiple GitHub/Bitbucket accounts with GitKraken?
However, with GitKraken Pro's multiple profile support, you can easily switch between profiles that each have their own associated GitHub and BitBucket accounts.
© 2024 OneMinuteCode. All rights reserved.