If you are new to web development or programming, you have probably heard people talk about GitHub. GitHub is the world’s most popular platform for hosting and managing code. It lets you store your projects, collaborate with others, and track the history of changes to your code. In this guide, I will walk you through everything you need to know to set up your first GitHub repository. You do not need any prior experience with Git or GitHub to follow along. By the end, you will have your first repository set up and ready to use.
What Is GitHub and Why Should You Use It?
Before we get into the steps, let’s take a moment to understand what GitHub is and why it matters. GitHub is a platform built on top of Git, a version control system created by Linus Torvalds. Git allows you to keep track of changes to your code over time, compare versions, and roll back if needed. GitHub takes this one step further by allowing you to host your code in the cloud, collaborate with others, and showcase your work to the world.
Whether you are building your portfolio, working on a personal project, or contributing to open source, having a GitHub account and knowing how to set up repositories is essential. Employers and fellow developers often look at GitHub profiles to understand your coding style, problem-solving skills, and project experience.
Prerequisites
To follow this guide, you will need the following:
- A computer with an internet connection.
- A GitHub account. If you do not have one, you can sign up for free at https://github.com.
- (Optional) Git installed on your computer if you want to interact with GitHub using your terminal or command prompt. This guide will cover both the web interface and basic command-line usage.
Step 1: Sign In to GitHub
Once you have created a GitHub account, go to https://github.com and sign in with your username and password. After logging in, you will see your GitHub dashboard. From here, you can manage your repositories, follow other developers, and explore projects.
Step 2: Create a New Repository
To create a new repository, click on the “+” icon at the top-right corner of the screen and select “New repository” from the dropdown menu. You will be taken to the repository creation page, where you need to fill in some details about your new project.
First, choose a name for your repository. This can be anything you like, but it is a good idea to choose a name that reflects the purpose of your project. For example, if you are building a personal website, you might name it portfolio-site
.
Next, you can optionally provide a description for your repository. This helps others understand what your project is about. For example, you might write “My personal portfolio website built with HTML, CSS, and JavaScript.”
You will then choose whether to make your repository public or private. A public repository can be seen by anyone on the internet. This is a good choice if you want to share your work, contribute to open source, or build a portfolio. A private repository can only be seen by you and the people you explicitly share it with. This might be useful for personal or experimental projects.
Finally, you can choose to initialize the repository with a README file. A README file is where you describe your project in more detail. It is usually the first thing people see when they visit your repository. For beginners, it is a good idea to check this option so your repository has some content from the start.
You can also add a .gitignore
file and choose a license, but for your first repository, you can leave these options alone unless you know you need them.
Once you have filled in these details, click the green “Create repository” button.
Step 3: Explore Your New Repository
After creating the repository, you will be taken to its main page. Here, you will see the README file (if you added one), and you will have access to several tabs such as “Code,” “Issues,” “Pull requests,” “Actions,” and “Settings.”
The “Code” tab is where you will see the files and folders that make up your project. Since this is a new repository, there may not be much here yet, but as you add files and make changes, this area will grow.
Step 4: Clone the Repository to Your Computer
While you can create and edit files directly on GitHub’s website, most developers prefer to work on code locally on their computer. To do this, you need to clone the repository.
To clone the repository, click the green “Code” button on the repository page. You will see a URL that you can copy. This is the address of your repository.
Open your terminal or command prompt and navigate to the folder where you want to store your project. Then run the following command, replacing the URL with the one you copied:
bashCopyEditgit clone https://github.com/your-username/your-repository-name.git
This command will download a copy of your repository to your computer.
Step 5: Add Files and Make Your First Commit
Once you have cloned the repository, you can add files to it using your text editor or IDE. For example, you might create an index.html
file for a website or a script.js
file for JavaScript code.
After adding or editing files, you need to tell Git to track these changes and upload them to GitHub. This process involves three steps:
First, stage the changes. In your terminal, run:
csharpCopyEditgit add .
This tells Git to add all new or changed files to the staging area.
Next, commit the changes with a message describing what you did:
sqlCopyEditgit commit -m "Add initial project files"
Finally, push the changes to GitHub:
perlCopyEditgit push
Now if you refresh your repository page on GitHub, you will see your files.
Step 6: Keep Working and Make More Commits
As you continue to work on your project, you will repeat the process of adding, committing, and pushing changes. Each commit represents a snapshot of your project at a particular point in time. This makes it easy to track progress, undo mistakes, and collaborate with others.
Step 7: Share Your Repository
One of the great things about GitHub is how easy it is to share your work. You can simply copy the URL of your repository and share it with employers, collaborators, or friends. If your repository is public, anyone can view your code and even suggest improvements.
If you want others to contribute to your project, you can enable features like issues and pull requests. These tools let people report problems, suggest changes, and collaborate with you on code.
Conclusion
Setting up your first GitHub repository is an important step in your journey as a developer. It gives you a professional space to store and share your code, collaborate with others, and build a portfolio of your work. Although the process may seem intimidating at first, once you have created a few repositories and made some commits, it will start to feel natural.
In this guide, you learned how to create a GitHub repository, clone it to your computer, add files, and push your work to the cloud. These are fundamental skills that will serve you well no matter what kind of projects you build in the future.
If you are ready to take the next step, consider learning more about Git branches, pull requests, and how to contribute to open source projects. In future posts, I will cover these topics in detail.
Suggested Next Steps
- Explore GitHub’s interface and features such as issues, pull requests, and GitHub Pages.
- Try creating another repository for a different project.
- Learn more about Git commands beyond
add
,commit
, andpush
.