DEV Community

Kelvin M.
Kelvin M.

Posted on

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

Introduction

We've all been there, you spend hours on or maybe days building something or working on a project in your local machine. In does exist somewhere in your desktop or some random folder, and each time you make some changes you just end copy pasting the contents of the folder and renaming it to some obscure name like "5th_Year_project_v3_Final_real".
This is where Git comes in to help turn your local experiment project into a clean trackable project with version control, tracking of changes and Github allows you to store your project online allowing others to see your work, collaborate with you on projects and also act as your resume for all the projects you've undertaken.
In our case we will use Git and SSH as a means of authenticating our local machine and enable us to connect to out Github accounts. Here is the simple way to get your local code/projects to GitHub using Git and SSH.

Step 1: Install Git & Create a GitHub Account

Before connecting anything, we need to have Git installed in our local machine as well as an active Github account.

1. Install Git on our computer

In our case we're using a windows computer and the installation process for Git is as follows:

  • Download the installer from Git and run it. The default setup options are recommended, just ensure to have "Git Bash" selected when installing.

  • Once the installation is complete, you can verify that it is installed by running the command below in your terminal

git --version
Enter fullscreen mode Exit fullscreen mode
  • A successful installation should show the git version installed in your computer as show below.
git version 2.55.0.windows.4
Enter fullscreen mode Exit fullscreen mode

2. Configure your identity in Git

Git needs to attach your name and email address to your commits so we need to set our name and email. It is recommended to use the email attached to your github profile.

git config --global user.name "Your Name"
git config --global user.email "your_email@example.com"
Enter fullscreen mode Exit fullscreen mode

3. Set up a GitHub Account

Go to github and click Sign up.
Type in your email, make a password, and pick a username, or simply just pick continue with google or apple for SSO login.

Github SignUp

Complete the quick verification puzzle and verify the launch code that was sent to your email.

Step 2: Turn Your Folder into a Git Repository

Now, we need to tell git to start monitoring what's going on in our project.
Open Git Bash, check your current path and navigate to where you've saved your project folder.

> pwd
> cd path/to/your/project-folder
Enter fullscreen mode Exit fullscreen mode

Initialize Git inside the directory:

git init
Enter fullscreen mode Exit fullscreen mode

This step creates a hidden .git folder inside your project, but we have a simple trick up our sleeve with the below command.

ls -lrt
Enter fullscreen mode Exit fullscreen mode

.git hidden file
Git is now watching but it hasn't saved a snapshot of your files yet. We now need to stage our files and make our first commit, but before then let's take a small detour.

Step 3: Set Up Your SSH Keys

An SSH key pair is like a physical lock and key. Your computer keeps the private key (and keeps it secret), and GitHub gets your public key. When they talk, GitHub verifies that you own the private key without ever asking for your password.

Create a key using the modern Ed25519 algorithm:

ssh-keygen -t ed25519 -C "your_email@example.com"
Enter fullscreen mode Exit fullscreen mode

When it asks you to “Enter a file in which to save the key,” just hit Enter to take the default path. You can include a passphrase to increase local security, ensure you set something you won't forget, or just hit Enter again to skip it.
You can confirm the key was generated by running:

ls -al ~/.ssh 
Enter fullscreen mode Exit fullscreen mode

You should see the following:

SSH key generated

We need to initialize our local ssh-agent and add our new key to it. The agent helps us manage our private SSH key as well remember the passphrase during our session.
Open PowerShell as an administrator on Windows and run:

Get-Service -Name ssh-agent | Set-Service -StartupType Manual 

Enter fullscreen mode Exit fullscreen mode

Then:

Start-Service ssh-agent 
Enter fullscreen mode Exit fullscreen mode

You can now close the PowerShell instance and open another normal instance of the same. To add our private SSH key run:

ssh-add c:/Users/USERNAME/.ssh/id_ed25519 

Enter fullscreen mode Exit fullscreen mode

And ensure to replace USERNAME with your actual set windows username. if you had set a passphrase enter in and confirm.

We need to copy our public key:
cat ~/.ssh/id_ed25519.pub | clip

Head over to Github:

  1. Click your profile picture at the top right and then click Settings. Click SSH and GPG Keys in the left sidebar. Click New SSH key. Give it a title like "My Lenovo Home Laptop" and paste your public key into the Key field. Click Add SSH key.

Test if it works by running and enter passphrase if prompted to:

ssh -T git@github.com
Enter fullscreen mode Exit fullscreen mode

If you get a response saying "Hi Username! You've successfully authenticated, but GitHub does not provide shell access.
", then you're ready to connect.

Step 4: Link Your Local Folder to GitHub

We're almost there just one last step for us o be fully logged in to Github and start pushing our project to our online repositories in Github.
Now, let's head to GitHub. Click the + sign in the top right corner and click New repository.

Choose a name for your repository, preferably the same as your local folder name. Don't add anything since we have code on our computer so we want a completely blank remote canvas.

Once it's created, head to the SSH tab on your new repository page and copy the URL (it should look something like git@github.com:username/repository-name.git).

Now, go back to your terminal and point your local folder to that remote GitHub repo and confirm connection:

git remote add origin git@github.com:username/repository-name.git
git remote -v
Enter fullscreen mode Exit fullscreen mode

One last step in our journey is stage all our files before performing our very first commit from our computer to Github:

git add .
git commit -m "Initial commit to add project files for data cleanup project"
git branch -M main
git push -u origin main
git log --oneline
Enter fullscreen mode Exit fullscreen mode

The Daily Workflow Quick Reference

Once you're set up, your day-to-day rhythm with Git comes down to four commands:

  • git status — Check what files you've modified or added.
  • git add . — Stage your recent changes.
  • git commit -m "Explain what you changed" — Save a milestone of your work.
  • git push — Upload your milestones to GitHub.

Summary

Completing your first Git push is not just a technical item checked off your to-do list, but the point at which your project leaves seclusion and enters an environment designed for contemporary software development. Git will help track your version history locally, and SSH will give you password-less, friction-less access to GitHub. We now have a clean, secure foundation that will support every line of code we write going forward allowing us not only to build projects locally but also collaborate with others and store our work online.

Top comments (0)