DEV Community

Victoria Ndei
Victoria Ndei

Posted on

My First GitHub Project: From a Local Folder to GitHub using Git and SSH

Introduction

This week I learnt how to create my first GitHub project from a local folder on my desktop using tools such as Git and an SSH connection. Git is used to track changes in the source code and files over time, while SSH is a key used for authenticating your desktop with your GitHub account. There are several steps that we need to follow before connecting our project to our GitHub account.

1 Creating a Folder

There are two ways to create a folder; the first way is to go to your file explorer and select Desktop to create the folder directly there. The second step is to use Git Bash. When using Git Bash, first, you run the command pwd to see which folder you're currently in; e.g when using Windows, you may see /c/Users/John _.To change your directory to Desktop, you run the command

cd Desktop
Enter fullscreen mode Exit fullscreen mode

Then run ls to see the files located on your desktop. Now we create our folder. To create a folder, we run

mkdir Kenya_Health_Records
Enter fullscreen mode Exit fullscreen mode

Then we run *cd Kenya_Health_Records * to change the directory to our folder.

2 Adding Files to The Folder

This is our second step after creating our folder. We are going to add the following folders to our project folder:

  • data

  • notebooks

  • scripts

To add the folders, we will run the following commands:

mkdir data

Enter fullscreen mode Exit fullscreen mode
mkdir notebooks
Enter fullscreen mode Exit fullscreen mode
mkdir scripts
Enter fullscreen mode Exit fullscreen mode

We will also add our README.md using the command:


touch README.md
`shell

Adding information to our README.md

To add information to our README, we use the echo command, two double quotes, and the> sign.
Example:

echo " ## My First GitHub Project" >README.md
shell
If you want to check that the information is added to the README.md file, we use


cat README.md
shell

3 Initializing the Project with Git

To initialize the project, we use the command git init
git init initializes the directory as a Git repository.
When I ran git init, it created a hidden .git directory inside my project to track changes.
Afterwards, I checked the status of my files using git status.

4 Stage the Whole Project

To stage the remaining changes to the whole project, I ran:


git add.
shell
The period (.) tells Git to add all files to the current directory. I ran *git status * to check if the files have been added.

5 Creating the First Commit

Run: git commit-m" Add Kenya Health Records`
git commit is a snapshot of the changes made to the project.

6 Check Current Branch

Run:

git branch
Enter fullscreen mode Exit fullscreen mode


shell
You may see *main, which is the current branch we are in.
For our beginner project, we will use main as our primary branch. If your branch says master, rename it using git branch -M main`

7 Creating GitHub repository

Sign in to your GitHub account and then click New repository.
Name your repository as Kenya-Health-Records.
You can choose whether to set it as private or public.
Our project already has a README.md, so do not select to add it to the repository.

8 Selecting SSH

After creating the repository, GitHub displays connection options like HTTPS and SSH.
Select SSH because it was already configured earlier.
The address will look similar to:git@github.com:USERNAME/kenyan-hospital-health-records.git

9 Connecting the Local Repository to GitHub

Open your git bash and run;


git remote add origin git@github.com:USERNAME/kenyan-hospital-health-records.git
shell
I replaced the username with my GitHub username.
I verified the remote connection using:
git remote-v

10 Pushing the Project to GitHub

Run:


git push -u origin main

git push sends the changes from my computer to my remote repository.

11 Verifying the Project on GitHub

After the push was completed, I went to GitHub and refreshed the page to see if my project files had been added to the repository.

Conclusion

I gained practical experience in how to upload my local folder using Git and SSH on GitHub. The experience was truly great, and now I'm more familiar with the tools, making it easier to work on more projects on my own from henceforth.

Top comments (0)