Hosting and Managing Code with GitHub
🎯 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
- Open GitHub (https://github.com) and click Sign up in the upper-right corner.
- Enter your username, email, and password, verify your email address, and sign in.
- Click “+” in the upper-right corner and select “New repository”.
- Enter a Repository name and choose Public or Private visibility.
- Optionally initialize a README file to give the repository a basic introduction.
- Click “Create repository” to finish.
🛠️ Setting up SSH authentication for GitHub
SSH authentication lets you work without entering your username and password for every operation, making development more efficient.
- Check for existing local SSH keys:
ls -al ~/.ssh
- 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.
- Display the public key so you can copy it to the clipboard:
cat ~/.ssh/id_rsa.pub
Copy the entire output.
- Sign in to GitHub and go to Settings -> SSH and GPG keys -> New SSH key.
- Give the key a name, paste the public key, and click “Add SSH key”.
- Test the SSH connection:
ssh -T git@github.com
A message starting with “Hi username! You've successfully authenticated” confirms that authentication works.
🚀 Pushing a local project to GitHub
Starting with an existing local project folder:
- Change to the project root:
cd your-project-folder
- Initialize a Git repository:
git init
- Stage all files for version control:
git add .
- Commit the code:
git commit -m "Initialize project"
- Add the remote repository (replace the URL with your repository's address):
git remote add origin git@github.com:your-username/your-repo.git
- Push the code to the remote repository:
git push -u origin master
✍️ Updating GitHub after changing your project
To synchronize local changes with the remote repository:
- Check the current status:
git status
- Stage the modified files:
git add .
- Commit the changes with a message describing the update:
git commit -m "Add a new feature"
- 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:
- Open the project's repository page on GitHub.
- Click the green “Code” button and copy the SSH or HTTPS URL.
- 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
- 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.
