How to generate ssh key and push a project to GitHub
Add files to your repository by commands in GitHub with public keys
Photo by Markus Spiske on Unsplash
GitHub gives a transport means ssh key to connect to your local computer. We can push our code file directly to the GitHub server with the help of such types of keys. It is very necessary to know pushing files from your local system to a global GitHub server. Git gives a platform for a developer to work properly, and securely on his code.
Here, we will see steps to put code files on GitHub by commands.
Check the installation of Git
First, check on your local computer whether Git is properly installed or not. If Git is properly installed on your local system with the proper user name and email, then go to the command prompt or terminal(relevant to your operating system).
generate ssh key
Key generation is an important way to connect GitHub to the local system. So go to the control panel or terminal and write
ssh-keygen
into the command line and press enter.It generates a pair of public/private keys.
Give the file name if you want to make key pair in a specific file otherwise press Enter button to go ahead.
If you already created any file of key pair, then it demands to overwrite them. write 'y' and press Enter again to go to the next step.
In the next step you will find 'Enter passphrase', simply press Enter to go to the next step.
Again press Enter in case of demanding a ' passphrase again'.
And you will find these results of key generation.
Copy public key pair code
Go to 'c' drive and open the 'Users' folder. again click on your computer user's name folder like this.
C>Users>(username folder)>.ssh>id_rsa.pub
If you are not finding the specific folder or file, then search in hidden files also and then you definitely will see the file.
Open the file and copy all the matters which is present in the file.
Setup ssh key in GitHub profile
Open your GitHub account and go to settings.
Click settings.
Click the 'New SSH key' button.
Write the title and paste the previously copied items.
Press 'Add SSh key'.
You will find these results.
Create a new repository
Click on the right corner to make a new repository.
Set up your repository name and other things.
Click on "Create repository".
Open VS Code to push files by command
Create a folder wherever you want to make the project. For example, i have created a folder named 'git-project' in my d drive.
Open VS Code and open the folder which you created currently.
Do your work like creating files and coding whatever you want to create.
And then open the terminal.
Follow git command
First, initialize the git by giving the command
git init
.Add the files to the git by giving the command
git add .
If you want to give only specific files then you can give the command with files names like
git add <filename>
.Then commit all changes by giving the command
git commit -m "message"
.Set up your branch to main by giving the command
git branch -M main
and then press enter.and you can see your branch by
git branch
command.Copy the repository command wherever you create your repository.
Paste the copied command into VS Code terminal and then press enter to run the command.
Again copy the command from the repository page.
Paste the copied command to your terminal.
and you will find push results.
Then go to your repository and reload the opened repository page and check repository files the files are pushed or not.