Day 8: Steps to Push Local Repo to GitHub Repo using SSH and PAT

Day 8: Steps to Push Local Repo to GitHub Repo using SSH and PAT

ยท

3 min read

Before we move into the steps to push the local repositories to remote repositories we have few prerequisite.

Prerequisites:

Create a repository in your local.

For creating a local repository, first create a directory in your filesystem named "localRepo".

cd into the localRepo directory and initiate the git repository using the command git init.

Now we have a repository created in our local system named 'localRepo'. Let's add one file named "feature1".

Now that we created a file in our local system, let's stage this file using the command "git add" and check the status using the "git status" command.

Once the file is moved to staging, we need to move it to the git repository so that the file can be tracked. This can be achieved using the git commit -m "" command, and then by using the "git log" command, we can check the commit logs.

Now our localRepo is ready.

Create SSH keys in your local system and paste it in GitHub

Create SSH keys using the command ssh-keygen in the .ssh directory.

Copy the SSH keys from the local system.

Go to settings and then click on SSH and GPG keys.

Paste the copied public key in the key field and click on Add SSH key.

Create a personal access token.

Please copy the personal access token that was generated and keep it safe (we will need this PAT later)

Create an empty repo in GitHub.

Steps to Push Local Repo to GitHub Repo using SSH.

Copy the SSH link from the GitHub repo created above and paste it in the command "git remote add origin".

Then hit the command "git push origin master".

Once done, check the GitHub page, the file feature1 created in your local system is now pushed to GitHub.

Steps to Push Local Repo to GitHub Repo using PAT.

Create a new repo in gitHub

Cd to our previously created localRepo repository and remove the origin variable's value

Add remote origin variable, for this first copy the http url of the gitHub repo 'PatDemorepo" and paste it in the command then add the copied PAT before the github url and after the https:// .Also dont forget to add "@" after the pasted PAT.

Now run command git push origin master

Check the gitHub repo, the feature1 file created in local has been pushed to "PatDemoRepo" repository


ย