Hosting and Managing Code with GitHub

Create a GitHub account, set up SSH authentication, push and update a local project, clone repositories, and explore GitHub's repository tabs.

🎯 Introduction

Whether you develop frontend applications or are just learning to program, managing code and collaborating are essential skills. GitHub is a widely used code hosting platform that helps you manage projects, share code, and work with teammates. This article walks you through creating an account, setting up SSH authentication, and pushing and updating projects. You can use this workflow for both personal projects and team repositories.


🔐 Creating a GitHub account and remote repository

  1. Open GitHub (https://github.com) and click Sign up in the upper-right corner.
  2. Enter your username, email, and password, verify your email address, and sign in.
  3. Click “+” in the upper-right corner and select “New repository”.
  4. Enter a Repository name and choose Public or Private visibility.
  5. Optionally initialize a README file to give the repository a basic introduction.
  6. Click “Create repository” to finish.
Choose a short, descriptive repository name that is easy for you and others to remember and find.

🛠️ Setting up SSH authentication for GitHub

SSH authentication lets you work without entering your username and password for every operation, making development more efficient.

  1. Check for existing local SSH keys:
ls -al ~/.ssh
  1. If you do not have a key, generate one with:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

Press Enter through the prompts to accept the defaults. The key files are saved as ~/.ssh/id_rsa and id_rsa.pub by default.

  1. Display the public key so you can copy it to the clipboard:
cat ~/.ssh/id_rsa.pub

Copy the entire output.

  1. Sign in to GitHub and go to Settings -> SSH and GPG keys -> New SSH key.
  2. Give the key a name, paste the public key, and click “Add SSH key”.
  3. Test the SSH connection:
ssh -T git@github.com

A message starting with “Hi username! You've successfully authenticated” confirms that authentication works.

Setting a passphrase when generating an SSH key is recommended for additional security, but it is optional.

🚀 Pushing a local project to GitHub

Starting with an existing local project folder:

  1. Change to the project root:
cd your-project-folder
  1. Initialize a Git repository:
git init
  1. Stage all files for version control:
git add .
  1. Commit the code:
git commit -m "Initialize project"
  1. Add the remote repository (replace the URL with your repository's address):
git remote add origin git@github.com:your-username/your-repo.git
  1. Push the code to the remote repository:
git push -u origin master
If the first push fails because of a permissions issue, check your SSH key configuration.

✍️ Updating GitHub after changing your project

To synchronize local changes with the remote repository:

  1. Check the current status:
git status
  1. Stage the modified files:
git add .
  1. Commit the changes with a message describing the update:
git commit -m "Add a new feature"
  1. Push to the remote repository:
git push

The remote repository now contains the update, and collaborators can pull the latest code.


👥 How others can clone your project

To get a local copy of your project:

  1. Open the project's repository page on GitHub.
  2. Click the green “Code” button and copy the SSH or HTTPS URL.
  3. Run this in a terminal:
git clone git@github.com:your-username/your-repo.git

Or:

git clone https://github.com/your-username/your-repo.git
  1. Git downloads the code to the local computer, ready to explore and develop.

🖥️ Understanding GitHub's repository tabs

GitHub repository pages include several useful tabs:

  • Code: displays the project's code and file structure.
  • Issues: tracks problems, tasks, and work to do.
  • Pull requests: proposes changes for review and merging, supporting team collaboration.
  • Actions: automates workflows such as testing and builds.
  • Projects: organizes project work in views such as Kanban boards.
  • Settings: manages repository configuration and permissions.

These features make GitHub useful for collaboration and project management as well as code hosting.


❓ Knowledge check

Q1: Why use SSH authentication?

SSH authentication avoids entering your username and password for each push or pull, making your workflow more efficient while providing secure authentication.

Q2: What is the difference between Git and GitHub?

Git is a version control tool that manages code history and changes. GitHub is an online platform built around Git for hosting code, collaboration, and sharing.

Q3: Can I use GitHub for private projects?

Yes. GitHub supports free private repositories that only authorized users can access.


🧪 Exercises

Exercise 1: Create a GitHub account and repository

Follow the steps in this article to register and create a repository named test-project.

Exercise 2: Push a local project to GitHub

Create a local folder named my-demo and add a simple index.html file. Initialize Git and push the project to the repository you just created.

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>My Demo</title>
    </head>
    <body>
        <h1>Hello GitHub!</h1>
    </body>
</html>

🎉 You now know how to create a GitHub account, configure SSH authentication, and push and update code! Use GitHub to manage and share your projects more efficiently.