Git & GitHub
Essential steps for setting up Git and GitHub
Version
git --version
User
Define your Git user (should be the same name and email you use for GitHub):
git config --global user.name "Your Name Here"
git config --global user.email "your_email@youremail.com"
They will get added to your .gitconfig
file.
SSH Config
First check for existing SSH keys on your computer by running:
ls -al ~/.ssh
Lists the files in your .ssh directory, if they exist
Check the directory listing to see if you have files named either id_rsa.pub or id_dsa.pub. If you don't have either of those files then read on, otherwise skip the next section.
Generate a new SSH key
Create .ssh
directory
mkdir ~/.ssh
Navigate to .ssh
directory
cd ~/.ssh
If you don't have an SSH key you need to generate one. To do that you need to run the commands below, and make sure to substitute the placeholder with your email. The default settings are preferred, so when you're asked to enter a file in which to save the key, just press Enter to continue.
ssh-keygen -t rsa -C "your_email@example.com"
Add your SSH key to the ssh-agent
Run the following commands to add your SSH key to the ssh-agent.
eval "$(ssh-agent -s)"
If you're running macOS Sierra 10.12.2 or later, you will need to modify your ~/.ssh/config
file to automatically load keys into the ssh-agent and store passphrases in your keychain:
add below code in ~/.ssh/config
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa
No matter what operating system version you run you need to run this command to complete this ste
ssh-add -K ~/.ssh/id_rsa
Adding a new SSH key to your GitHub account
The last step is to let GitHub know about your SSH key so GitHub can recognize you. Run this command to copy your key to your clipboard:
pbcopy < ~/.ssh/id_rsa.pub