DEV Community

Brian Kariuki
Brian Kariuki

Posted on

My First Github Project: From A Local Folder To Github Using Git And SSH.

Git and Github

Github is a website and cloud-based platform where users may store, exchange, and collaborate on computer code. It makes use of Git, a program that keeps track of file changes over time.

Creating Project Folder

I first created a new project using Gitbash called Kenya-Health-Records-Analysis using the mkdir make directory command.

Steps I took:

  • Navigated where I want project stored (cd ~/Desktop)
  • Created the project folder (mkdir Kenya-Health-Records-Analysis)
  • Enter the created folder (cd Kenya-Health-Records-Analysis)

Inside the Kenya-Health-Records-Analysis folder, I created an additional folder called data (mkdir data) and a file README.md (touch README.md)

Inside the data folder I added a Kenya_Hospital_Health_Records xlsx file.

User Guide To Our First Project

Our README.md file serves as introduction or user guide to our project. I opened and edited it in gitbash by running nano README.md

Steps I took

  1. Navigated to the Project Folder cd Kenya-Health-Records-Analysis
  2. Typed open command nano README.md
  3. Edited text insided the terminal window explaining our project.
  4. Saved changes ctrl+o then Enter
  5. Exit nano ctrl+x

Creating our Github Account

As stated earlier, Github is a cloud-based platform where users may store, exchange, and collaborate on computer code. It makes use of Git, a program that keeps track of file modifications over time to prevent you from losing previous work or becoming confused by different stored versions. I used my email to create Github, set a good password, chose the Github free tier and customized my profile.

Set Up SSH for GitHub

SSH enables secure communication between my computer and Github without requiring me to input my Github username and password each time I push changes.

Steps I took

  • Checked whether I already have an SSH key by running ls -al ~/.ssh, In my case I didn't have one.
  • I created a new SSH key by running ssh-keygen -t ed25519 -C "your-email@example.com" , replaced email with the email address connected to my GitHub account.
  • Created an SSH passphrase.

Add SSH Key to the SSH Agent

  • Started the SSH agent by running eval "$(ssh-agent -s)"
  • Then added my private SSH key ssh-add ~/.ssh/id_ed25519

Add Public SSH Key to GitHub

  • Show my public SSH key by running cat ~/.ssh/id_ed25519.pub
  • Copy the Public SSH Key.
  • Open GitHub and go to Settings, then select SSH and GPG keys.
  • Click New SSH key, enter a descriptive title such as My laptop, and paste the public SSH key into the key field.

Test SSH Connection

Tested whether GitHub recognizes my SSH key by running, ssh -T git@github.com. My case I was asked to confirm GitHub's host by typing yes. GitHub displayed a successful authentication message.

Open Project Folder

I navigated to the folder containing my project, cd Kenya-Health-Records-Analysis
I confirmed that I'm in the correct folder by listing its contents, ls

Initialize Git in Local Project

Inside my project folder, I initialized Git by running, git init, this command creates a new local Git repository and allows Git to begin tracking changes to your project files.
Checked the repository status by running, git status

Add Project Files to Git

Added all files in the current project folder to Git by running, git add .
Checked whether the files are ready to be committed by running git status

Create First Commit

Commit main goal is to permanently store your project in your local repository history, I run git commit -m "Initial commit".

Create a New Repository on GitHub

Inside Github, I selected New repository,entered a name for my project, chose whether the repository should be Public or Private and clicked Create repository.

Connect Local Project to GitHub

In GitHub repository created, I clicked SSH and copied the URL.
I connected local repository to gitHub by running, git remote add origin git@github.com:YOUR-USERNAME/Kenya-Health-Records-Analysis, replaced USERNAME with my actual github username.
I verified that the remote repository was added successfully by running, git remote -v.

Push Project to GitHub

Pushed my project to GitHub by running, git push -u origin main
Project files were visible in my GitHub repository.

Top comments (0)