logo
podcast Podcast
get help Get Unstuck

Another way to use different SSH keys for different git repos

git truly does it all

Joel Clermont
Joel Clermont
2025-07-29

I previously shared a tip on using different SSH keys per git repo.

This led to some feedback from Hammed Oyedele with a related situation that requires a different solution.

What if the repo needing a specific SSH key is a privately-hosted package used in your project's composer.json file?

You can't as easily manipulate the URL to match your local SSH config since it would require everyone on the team to agree to the same SSH alias, as well as your CI and other environments. It might be possible, but it's certainly not ideal.

Instead, we need to add one more step to our previous tip, and update our global git config, typically found at ~/.gitconfig:

[url "bitbucket-work-alias:work-organization"]
    insteadOf = [email protected]:work-organization

With this in place, any git commands we run, including that Composer install, that have a URL starting with [email protected]:work-organization will automatically be rewritten with our local SSH alias bitbucket-work-alias.

It's important to include the work-organization to limit this replacement logic to just that specific user or organization.

If we had more than one org or user to match, we could add additional sections to our global git config to cover them all.

Now we can seamlessly use our local SSH alias without requiring the rest of our team to change their local configuration.

Here to help,

Joel

P.S. Would you like help getting your project off an older PHP or Laravel version, but without breaking anything?

Toss a coin in the jar if you found this helpful.
Want a tip like this in your inbox every weekday? Sign up below 👇🏼
email
No spam. Only real-world advice you can use.