GitHub Setup

Posted on February 08, 2025 in Tech-Recipe

[!NOTE] The environment used for this was: Mac Air M2 8gb MacOS Sequoia 15.3

Notes on GitHub Setup

General git config that works for me...

git config --global init.defaultbranch main
git config --global color.ui true
git config --global fetch.prune true
git config --global diff.colorMoved zebra
git config --global pull.rebase false

Make a new ssh key

Make a ssh key for authentication:

ssh-keygen -a 100 -t ed25519 -C "jas@business.com" -f jas-business-github-key-ed25519

Upload the ssh key to your GitHub acount, and test with:

ssh -i jas-business-github-key-ed25519 -T git@github.com

And GitHub should reply with:

Hi jas-business! You've successfully authenticated, but GitHub does not provide shell access.

Reset ssh-agent issue

So, sometimes when you run:

ssh -i jas-business-github-key-ed25519 -T git@github.com

And GitHub should reply with:

Hi jas-business! You've successfully authenticated, but GitHub does not provide shell access.

But instead you see:

Hi jas-PERSONAL! You've successfully authenticated, but GitHub does not provide shell access.

And you're confused because you definitely used the right key and when you run git config user.name you see the right user name, it may be because the ssh-agent got confused between terminal windows, sigh!

Do this:

killall ssh-agent; eval `ssh-agent`

and sanity will be restored!

Adding keys to the local git config

If you are git clone-ing a existing project that needs your new key1, use a line like this one:

ssh-agent $(ssh-add jas-business-github-key-ed25519; git clone git@github.com:user/project.git)

And if you work on different projects for business and for personal, in the directory of the project2:

git init
git config --local user.name "jas"
git config --local user.email "jas@business.com"
git config --local core.sshCommand "ssh -i jas-business-github-key-ed25519"

References


  1. https://stackoverflow.com/questions/4565700/how-to-specify-the-private-ssh-key-to-use-when-executing-shell-command-on-git 

  2. https://dev.to/web3coach/how-to-configure-a-local-git-repository-to-use-a-specific-ssh-key-4aml