Easy Guide To Integrate Local Git with GitHub
Do you want to push your local Git repository on the GitHub? Or do you want to pull changes in the remote repository (GitHub) to local repository ?
To do so, we need connection btw the local Git and the GitHub.
Quick Recap : Git is a distributed version control software that allows users to maintain the workflow of Git repositories locally on their machines. GitHub, on the other hand, is a website and cloud-based platform where users can host Git repositories and collaborate with others through features like pull requests and issue tracking.
Now we took quick recap over what is Git and GitHub? So let's learn how to establish connection btw the Git and GitHub. One of the most secure and easy way to establish this connection is
via the SSH one can push, pull, clone, fetch the git repositories.
You might be thinking that what is this SSH?
SSH is also a protocol which we used to connect to server via internet like HTTPS. SSH normally used to automate the authentication process. It uses the public-private key pair.
Now that you've become a bit more familiar with SSH. Let's see How to establish connection with SSH.
Let's Get Started ๐ค.
First change the remote-url from HTTPS to SSH by using the following command.
#replace your username and repo git remote set-url origin git@github.com:YOUR_USERNAME/YOUR_REPOSITORY.git
Now check for existing SSH-key
#Lists the files in your .ssh directory, if they exist ls -al ~/.ssh
If key exits, skip the key-generation process. Else to generate the ssh key, follow below commands.
#Generate SSH key ssh-keygen -t ed25519 -C "your_email@example.com" #Output >vEnter a file in which to save the key (/home/YOU/.ssh/id_ALGORITHM): [Press enter] #At the prompt, type a secure passphrase.If you want to or leave null #by pressing enter. #To Check is ssh-key is gernerated or not use below command ls -al ~/.ssh #you will see two file with same name one with .pub the public key #another without any extension the private key.
Add your SSH-key private key to SSH-agent
#Start the ssh-agent in the background. eval "$(ssh-agent -s)" #output : Agent pid 59566 #Add your SSH private key to the ssh-agent. ssh-add ~/.ssh/id_ed25519
Add your public key to your GitHub account
#Copy the SSH public key to your clipboard. cat ~/.ssh/id_ed25519.pub
- Now go to GitHub account settings.
Click on SSH-key or GPG-key.
- Click on New SSH key.
- In the "Title" field, add a descriptive label for the new key. Select the type of key, either authentication or signing. In the "Key" field, paste your public key. Click Add SSH key.
Test SSH connection.
# Attempts to ssh to GitHub ssh -T git@github.com #You may see a warning like "> The authenticity of host 'github.com (IP ADDRESS)' can't be established. #> ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU. #> Are you sure you want to continue connecting (yes/no)? [TYPE yes] #you will get output as > Hi USERNAME! You've successfully authenticated, but GitHub does not > provide shell access.
Congrats ! You're done.
That's How we are established SSH connection between git and GitHub successfully.
Stay Curious ๐ !!!
Subscribe to my newsletter
Read articles from Vrushali Kudande directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by