Saturday, October 15, 2022
HomeWordPress DevelopmentA number of github accounts - DEV Group 👩‍💻👨‍💻

A number of github accounts – DEV Group 👩‍💻👨‍💻




What’s the use case?

Not too long ago my firm moved all of the repositories from a privately hosted git repository to an enterprise github account. Which means all the corporate repositories have now area github.com, the identical as all my non-public ones.
Because it quickly turned evident the corporate github credentials and related ssh key would inevitably conflict with my non-public github account on not one, however two fronts. I couldn’t use one occasion of my browser to work together with my non-public and my firm’s repositories concurrently. This was simply solved by dedicating one of many browsers (in my case it was opera) to all firm issues whereas I saved firefox for all my private associated issues.
Nonetheless as most others I additionally use ssh key to entry git repositories moderately than credentials and right here I run into few challenges.



GIT cli

To make lengthy story brief git-cli makes use of ssh-agent to authenticate to git supplier. It appears to be like up the cached ssh keys and tries them one after the other from high to backside.

If the hot button is not cached it should look into the .ssh listing. That is why it should work even in the event you delete the important thing pair from there. Extra on that is to be discovered on handbook pages of ssh-add.

The primary key which manages profitable authentication is for use even when it does not match the organisation used within the github url.

Right here is the url construction of repository hosted on github:

git@github.com:Organisation/repository.git
Enter fullscreen mode

Exit fullscreen mode

If the primary ssh key’s the non-public one – not one of the firm accounts(until made public) could be accessible.

If the primary ssh key’s the corporate one – the whole lot will work aside accessing the non-public repos underneath the non-public account.
The general public repos underneath non-public account will nonetheless be accessible to clone, however almost definitely (relying on the repository setup) github will reject any direct adjustments.
You most likely would be capable of create a brand new department and to open PR albeit not underneath you non-public identify, however underneath the identify you employ on the corporate account.



Answer 1 – gitconfig

the answer is utilizing the native .gitconfig settings.
for personal venture dedicate a separate folder and create native config file.

in case you are on a linux machine the default config could be in your house listing

~/person/residence/myname/.gitconfig
Enter fullscreen mode

Exit fullscreen mode

and all of the non-public “stuff” might want to have a devoted .config .

~/my-private-projects/.gitconfig
Enter fullscreen mode

Exit fullscreen mode

Though this isn’t picked mechanically by git. Git doesn’t work the identical means as e.g. pip in python
the place it will traverse the present and oldsters direcotries for config.

It must be specified within the “foremost” .gitcofnig file:

[user]
    e-mail = companyID@firm.com
[core]
    editor = nvim
    sshCommand = ssh -i ~/.ssh/id_rsa_company
[includeIf "gitdir:~/private-projects/"]
    path = ~/private-projects/.gitconfig
Enter fullscreen mode

Exit fullscreen mode

The essential bits are person.e-mail and core.sshCommand
this fashion we are able to instruct github to make use of particular sshKey for this whole folder and sub-folders.

If the ssh key will not be specified the ssh service will match the primary out there ssh key working with github area as described above.



Answer 2 – ssh config

This answer is utilizing .ssh/config. Documentation for ssh config.
If it does not exist (which it most likely does not in the event you get this far), create it and add one thing
alongside these traces

Host github-work
    Hostname github.com
    # Username for distant SSH person (For GitHub, everybody makes use of the identify `git`)
    Consumer git
    IdentityFile /residence/person/.ssh/id_rsa_company
    IdentitiesOnly sure

Host github.com
    Hostname github.com
    Consumer git
    IdentityFile /residence/person/.ssh/id_rsa_private
    IdentitiesOnly sure
Enter fullscreen mode

Exit fullscreen mode

Few issues right here is price to say Keep in mind this?

git@github.com:Organisation/repository.git
Enter fullscreen mode

Exit fullscreen mode

and your non-public git repos are almost definitely having very an identical type:

git@github.com:your-git-name/repository.git
Enter fullscreen mode

Exit fullscreen mode

The host right here is github.com in each circumstances. The host github-work truly could possibly be something however you would want manually change the github.com to
github-work within the .git/config file of the prevailing repository, or change that half when you’re cloning the repository as following:

git clone git@github-work:Organisation/repository.git
Enter fullscreen mode

Exit fullscreen mode

I left the opposite one as github.com as there could be no additional actions wanted for all of the non-public repositories.
You may do it the opposite means on you’re employed machine or you might use “alias” for each or all organizations it’s good to entry with separate identities.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments