Skip to content

Latest commit

 

History

History
293 lines (204 loc) · 7.56 KB

File metadata and controls

293 lines (204 loc) · 7.56 KB

Setting up Git & GitHub on your computer

This document will help you to setup your computer to use Git & GitHub for your projects.

Prerequisites

Download & Install Git for your operating system from https://git-scm.com/downloads

While setting up the installation for Git it is preferable follow the below recommendations:

  • For Choosing the default editor used by Git select any GUI based text editor that you are comfortable with
  • For Adjusting the name of the initial branch in new repositories select Override the default branch name for new repositories
  • For Configuring the experimental options check both Enable experimental support for pseudo consoles and Enable experimental built-in file system monitor

Create an account on Github.com

Method 1: Using GitHub CLI (Recommended)

GitHub CLI is GitHub's official open source tool for using GitHub directly from computer's command line & hence provides an easy to use credential system.

Download & Install GitHub CLI

winget install --id GitHub.cli

Close & reopen the terminal window after installation for the command to be available

brew install sh
  • For Linux (Ubuntu & other Debian based distros):
sudo apt install gh
  • For Linux (Fedora & other RHEL based distros):
sudo dnf install gh

Logging into GitHub account

After installing GitHub CLI, execute the following command to login with your GitHub account

gh auth login
  • account type: GitHub.com
  • preferred protocol: HTTPS
  • Authenticate Git with GitHub credentials: Yes
  • Authentication method: Login with a web browser

Copy the one-time code provided in the terminal & paste it in the browser window opened for logging in.

🎉 You've successfully connected your GitHub account to Git on your computer. Verify using gh auth status

Method 2: Using SSH

Add your username & email to git config

Execute the following commands with your github account credentials to let git know your username & email

git config --global user.name <YOUR_USERNAME>
git config --global user.email <YOUR_EMAIL>

Set up SSH

Follow the instructions for your operating system.

For Windows

Generating a new SSH key

  1. Open Git Bash
  2. Paste below text, with your GitHub email address, for generating a SSH key
ssh-keygen -t ed25519 -C "your_email@example.com"
  1. Accept default choices by pressing enter on prompts
  2. You've successfully created your SSH key, next add your key to ssh-agent

Adding SSH key to ssh-agent

  1. Ensure ssh-agent is running by running first line of below text
eval "$(ssh-agent -s)"

Agent pid 59566

If you see a similar output, proceed to next step

  1. Add your SSH private key to ssh-agent
ssh-add ~/.ssh/id_ed25519

Adding SSH key to your GitHub account

  1. Copy public key to your clipboard
clip < ~/.ssh/id_ed25519.pub
  1. Go to GitHub website and click on your profile photo, then click Settings
  2. In the "Access" section of the sidebar, click SSH and GPG keys
  3. Click New SSH key or Add SSH key
  4. In the "Title" field, add a name of your choice for your computer.
  5. In the "Key field", paste your public key.
  6. Click Add SSH key
  7. If prompted, confirm access to GitHub account

Testing your SSH connection

  1. Execute the following code in git bash
ssh -T git@github.com
  1. If a warning pops up, type yes
  2. You should see a message similar to this, with your username
> Hi USERNAME! You've successfully authenticated, but GitHub does not provide shell access
For MacOS

Generating a new SSH key

  1. Open Terminal
  2. Paste below text, with your GitHub email address, for generating a SSH key
ssh-keygen -t ed25519 -C "your_email@example.com"
  1. Accept default choices by pressing enter on prompts
  2. You've successfully created your SSH key, next add your key to ssh-agent

Adding SSH key to ssh-agent

  1. Ensure ssh-agent is running by running first line of below text
eval "$(ssh-agent -s)"

Agent pid 59566

If you see a similar output, proceed to next step

  1. If using 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.
  • First, check if file already exists in the default location
open ~/.ssh/config
  • If file doesn't exist, create the file
touch ~/.ssh/config
  • Open the file and modify it to contain the following lines.
Host github.com
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_ed25519
  1. Add your SSH private key to ssh-agent
ssh-add --apple-use-keychain ~/.ssh/id_ed25519

Adding SSH key to your GitHub account

  1. Copy public key to your clipboard
pbcopy < ~/.ssh/id_ed25519.pub
  1. Go to GitHub website and click on your profile photo, then click Settings
  2. In the "Access" section of the sidebar, click SSH and GPG keys
  3. Click New SSH key or Add SSH key
  4. In the "Title" field, add a name of your choice for your computer.
  5. In the "Key field", paste your public key.
  6. Click Add SSH key
  7. If prompted, confirm access to GitHub account

Testing your SSH connection

  1. Execute the following code in terminal
ssh -T git@github.com
  1. If a warning pops up, type yes
  2. You should see a message similar to this, with your username
> Hi USERNAME! You've successfully authenticated, but GitHub does not provide shell access
For Linux

Generating a new SSH key

  1. Open Terminal
  2. Paste below text, with your GitHub email address, for generating a SSH key
ssh-keygen -t ed25519 -C "your_email@example.com"
  1. Accept default choices by pressing enter on prompts
  2. You've successfully created your SSH key, next add your key to ssh-agent

Adding SSH key to ssh-agent

  1. Ensure ssh-agent is running by running first line of below text
eval "$(ssh-agent -s)"

Agent pid 59566

If you see a similar output, proceed to next step

  1. Add your SSH private key to ssh-agent
ssh-add ~/.ssh/id_ed25519

Adding SSH key to your GitHub account

  1. Copy public key to your clipboard
cat ~/.ssh/id_ed25519.pub
# Select & copy the contents of the id_ed25519.pub file
# displayed in the terminal to your clipboard
  1. Go to GitHub website and click on your profile photo, then click Settings
  2. In the "Access" section of the sidebar, click SSH and GPG keys
  3. Click New SSH key or Add SSH key
  4. In the "Title" field, add a name of your choice for your computer.
  5. In the "Key field", paste your public key.
  6. Click Add SSH key
  7. If prompted, confirm access to GitHub account

Testing your SSH connection

  1. Execute the following code in terminal
ssh -T git@github.com
  1. If a warning pops up, type yes
  2. You should see a message similar to this, with your username
> Hi USERNAME! You've successfully authenticated, but GitHub does not provide shell access

Found a mistake or have other improvement for this guide?
Submit a Pull Request!