DEV Community

Shikothetechgirl
Shikothetechgirl

Posted on

My First Github Project: From a Local Folder to Github Using Git and SSH

Introduction

Github and Git are commonly used in software and data projects to organize work, track changes and collaborate easily with project contributors. Github is a cloud based web platfrom where users can store and manage code while Git is the local software tool used to track changes in the code. in this article, I will demostrate how to move a project from a local folder using Git to Github while using SSH.SSH is the secure authentication channel that will allow our computer to communicate to Github without requiring authetication of a username or password each time.

Setting Up Git

Before uploading the project to Github, we will configure Git on the local machine. This will establish the default branch or channel that will be used.

Configuring the Git Username and Email

After downloading Git, we will assign the user name and email address for our commits.

git config --global user.name "Your Name"
git config --global user.email "your_email@example.com"
git config --global init.defaultBranch main

The --global option will apply the above settings to all the Got repositories and they will not be limited to the current project. To verify the configurations, we will use git config --global --list.

Setting up Github and SSH Authentication

After configuring Git, which will track changes to our project locally, we will configure Github which will manage and store our Git repositories on the cloud. To create a communication channel between the two, we will use SSH authentication. SSH is a secure communication protocal which will allow our computer to authenticate itself to Github.

Checking for Existing SSH Keys & Generating an SSH Key

We will run ssh -V in Git to display the SSH version running in our computer. Let's also check for any existing SSH keys by running ls -la ~/.ssh

Although we already have an SSH key, we will generate a new one by using ssh-keygen -t ed25519 -C "project@example.com". We will be prompted to specify the file to save the key and also set up a passphrase for it. The public key we will use for github will be stored in the .pub file. We should then verify the key exists by ls -la ~/.ssh.

To display the contents of the public key created, we will run cat ~/.ssh/id_ed25519_keyname.pub which will return the key

Adding our Public SSH key to Github

Assuming you already have a Github account, we will navigate to settings, SSH and PG Keys then select New SSH Keyand add the public SSH key copied from Git Bash. Don't forget to give it a descriptive title. With this, Git and Github have a secure communication channel.

Testing the SSH Connection to GitHub

To test that we have SSH connection between Git and Github, we will run ssh -T git@github.com and receive below successful connection message.

Initializing our local Folder as a Git Repository

Before we push anything to Github, we will ensure we create a folder which containers folder data and a README.md file.

We have used the below commands:

  • mkdir "Data Science -make a folder called Data Science

  • cd Data Science -change directory to data science folder

  • pwd - print the current working directory

  • mkdir data - create a subfolder called data

  • touch README.md - create a file name which uses Markdown. This file will describe the project and other information related to it.

Initializing the Repository

To initialize Git in this folder, we will run git init. This will create an empty .git folder which will store information Git will use to manage the project.

Adding Data to the Data Folder & Staging

After this verification, we will add an excel file into the data folder. The excel file contains health data. To stage we will use git add . After this, our project is ready for the fist commit

Git Commit

The commit step does not upload the project to Github yet. It is still stored locally in the computer. To send the project to Github, we will use git push

Creating a Github Repository (Repo)

For this step, we will go to Github, Home - New - then create repository


After that, we will connect the local Git repo to our remote repo in Github. This creates a matching to where projects will be uploaded and where changes can be gotten from (fetching & pushing. We also verified the connection using git remote -v.

Pushing our Local Repository to Github

Since both the repositories are connected, we can now push the local project files to Github using git push -u origin main

Verify the Project on GitHub

After pushing the repo to Github, we will check the empty remote repository in Github to confirm the local repo was pushed successfully.

Creating new changes through READ.ME file modification

The README.md file provides information about the project. Let's add a description and push the changes to Github
We will use the command nano README.md add the text

cat README.md to display the changes made to the file

Adding the changes, Committing and pushing to Github

The screenshot below shows that the changes we made have been successfuly pushed to Github

Conclusion

In this article, we went through the process of setting up Git and GitHub. We configured Git, set up SSH authentication, created a local repository then configured Github as the remote repository where we pushed all the work. The article shows the Git workflow from making changes, staging, committing and pushing. This will ensure easy project tracking and changes management. Additionally, other users can also see and contribute to our project.

Top comments (0)