I'm setting up my dev environment on my new machine (m2 Mac) and have setup the ~/.gitconfig
~/.gitconfig-work
and ~/.ssh/config
to separate my ssh keys for personal and professional use.
~/.gitconfig
[user]
name = personal-username
email = personal-email@gmail.com
IdentityFile = ~/.ssh/id_rsa
[includeIf "gitdir:~/Documents/work/"]
path = ~/.gitconfig-work
[init]
defaultBranch = main
~/.gitconfig-work
[user]
name = work-username
email = work-email@work.com
IdentityFile = ~/.ssh/id_rsa_work
~/.ssh/config
Host github.com-personal
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
IdentitiesOnly yes
# Work
Host github-work
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_work
IdentitiesOnly yes
I add the keys to the ssh agent and cloning works fine provided I update the remote url to have the correct host field e.g git clone git@github-work:work/work-repo.git
Now the company that I work for have some npm packages that are the base of majority of our projects, simply running npm install
would always work on my previous mac, but now when running npm install I get the following error
npm install
npm ERR! code 128
npm ERR! An unknown git error occurred
npm ERR! command git --no-replace-objects ls-remote ssh://git@github.com/work/work-private-repo.git
npm ERR! ERROR: Repository not found.
npm ERR! fatal: Could not read from remote repository.
npm ERR!
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.
npm ERR! A complete log of this run can be found in:
Im using node v16.16.0
& npm v8.11.0
, have tried with node 14 & 12 and neither worked.
Im trying to figure out the difference between the dev setup from both machines but haven't found any differences.
From the error the issue is when trying to call
git --no-replace-objects ls-remote ssh://git@github.com/work/work-private-repo.git
When I update the remote call to
git --no-replace-objects ls-remote ssh://git@github-work/work/work-private-repo.git
to match my work profile and keys, it will return a valid response.
The package.json entry for the repo which can't be found is
"work-private-repo": "git+https://github.com/work/work-private-repo.git",