npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

git-multi-profile

v1.0.4

Published

A command-line utility to easily work with multiple git accounts. Automatically use the correct SSH key and user profile for git operations without having to remember any extra steps.

Downloads

3

Readme

LicenseDownloads

A command-line utility to easily work with multiple git accounts.

Automatically use the correct SSH key and user profile for git operations without having to remember any extra steps. Once configured, it just works. Easy peasy 🍋

No more cases of mistaken identity or "Permission Denied" when trying to access a repo when you have multiple git accounts.

The following configuration was done on MacOS

Installation

npm i -g git-multi-profile

Global install is important here since this will be used outside the scope of any individual NodeJS project

Set up

# Download shell script
curl -Lo git-clone https://raw.githubusercontent.com/AdaptableBytes/git-multi-profile/main/shell-scripts/git-clone

# Make available as shell command
sudo cp git-clone /usr/local/bin && sudo chmod +x /usr/local/bin/git-clone

Config

Create a new config file in user home directory with your account info.

This file is used exclusively by git-multi-profile so there is no risk for conflicts or disrupting existing git functionality.

~/.git-profiles.json

{
  "personal": {
    "name": "Name or Username",
    "email": "[email protected]",
    "hostprefix": "personal"
  },
  "work": {
    "name": "Name or Username",
    "email": "[email protected]",
    "hostprefix": "work"
  }  
}

Add/Create SSH Keys

If you don't already have SSH keys configured for your git accounts, create an SSH key for each profile you set up in ~/.git-profiles.json

ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa_personal -C "[email protected]"

ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa_work -C "[email protected]"

Add your SSH Key to your Github account

Github Doc

Configure Local SSH Key Mapping

Open ~/.ssh/config file. Add entries as follows (one for each profile you set up in ~/.git-profiles.json)

Host personal.github.com
  HostName github.com
  User git
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_rsa_personal

Host work.github.com
  HostName github.com
  User git
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_rsa_work  

Usage

Use the following command in place of the usual git clone command

git-clone {PROFILE} {GIT_REPO_SSH_URL}

This will perform a git clone operation for the specified repo and update the local .git/config with the profile user

Example

git-clone work [email protected]:MyCompany/some-repo.git

From the command-line, you are using the shell script command, not the NodeJS library directly

Additional Resources

  • Add SSH Key to Gitlab https://docs.gitlab.com/ee/ssh/README.html#adding-an-ssh-key-to-your-gitlab-account

  • Add SSH Key to BitBucket https://support.atlassian.com/bitbucket-cloud/docs/set-up-an-ssh-key/

FAQ

What does git-multi-profile do with SSH keys?

Nothing. The core functionality is performed by git and ssh. git-multi-profile is a thin wrapper that maps the hostname to a configured git profile and then invokes git which in turn uses ssh for communication

Will git-multi-profile work with Bitbucket, Gitlab, other?

Yes. This works with any git provider assuming they are utilizing the standard protocols

Help! The command says "cloning..." but just hangs.

This is likely because you don't have the Git provider in your ssh known-hosts file, and an ssh prompt is waiting for input. This is annoying, but a necessary security check.

To solve this you could run ssh command to the hostname like so (of course enter the actual git provider hostname and port, which is usually 22):

ssh [email protected] -p 2022

which will generate the prompt like this:

The authenticity of host '[source.developers.google.com]:2022 ([xx.xx.xx.255]:2022)' can't be established.
ECDSA key fingerprint is SHA256:AGmEpqXNMqsRPIviwyk4J4HM0lEylomDBKOWZsBb434.
Are you sure you want to continue connecting (yes/no/[fingerprint])?

Say "yes" which will add the host to your known-hosts file.