How to setup your Git, Github account on another computer
Let’s imagine that you need to use another computer to do some development work on one of your Github projects but you don’t have your computer at hand to copy your private key over. What to do then?
Generate a new SSH key
The first step is to generate a new key in your console like this:
$ ssh-keygen -o -t rsa -C "email@example.com"
make sure to substitute
firstname.lastname@example.org with your personal email when generating the key.
When asked where do you want to store your new key, press
Enter to store it on the default location.
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/username/.ssh/id_rsa):
You will be asked to enter a passphrase(password) to protect your key. This step is optional and you can keep it blank to skip this.
Enter passphrase (empty for no passphrase):Enter same passphrase again:
Add public key to Github
After generating the key login into your Github account, go to your
Account Settings by clicking the Profile Image icon on the right and selecting Settings on the displayed Menu:
In your Settings page look for SSH and GPG keys:
and click on New SSH Key:
Then go back to your terminal and print the content of your public key for the recently generated key pair:
$ cat ~/.ssh/id_rsa.pub
This should output something similar to this:
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA879BJGYlPTLIuc9/R5MYiN4yc/YiCLcdBpSdzgK9Dt0Bkfe3rSz5cPm4wmehdE7GkVFXrBJ2YHqPLuM1yx1AUxIebpwlIl9f/aUHOts9eVnVh4NztPy0iSU/Sv0b2ODQQvcy2vYcujlorscl8JjAgfWsO3W4iGEe6QwBpVomcME8IU35v5VbylM9ORQa6wvZMVrPECBvwItTY8cPWH3MGZiK/74eHbSLKA4PY3gM4GHI450Nie16yggEg2aTQfWA1rry9JYWEoHS9pJ1dnLqZU3k/8OWgqJrilwSoC5rGjgp93iu0H8T6+mEHGRQe84Nk1y5lESSWIbn6P636Bl3uQ== email@example.com
copy this to your clipboard and paste it on Github adding a descriptive title:
Setup your Git
Now you have granted access to Git for our Github account on this computer is time to setup Git so commits, pull requests, etc… appear on Github with our name.
First, clone your project and pull it to the computer:
git clone firstname.lastname@example.org:testing/TestingApp.git
and then run these commands to configure Git for this project:
$ git config user.name "Mona Lisa"
$ git config user.email "email@example.com"
$ git config user.username "myusername"
Doing this you will modify the Git configuration of the project that is stored in
.git/config. After this confirm that your setup is OK by running:
$ git config --list
and you should see this output:
With these three simple steps, you can setup your Github account and Git configuration on another computer.
I hope this tutorial was helpful and if you have any questions just let me know on the comments.