DEV Community

Cover image for A Beginner’s Guide to GitHub
Kiran Baliga
Kiran Baliga

Posted on

A Beginner’s Guide to GitHub

As a student just starting out in the world of coding, I found GitHub to be a bit overwhelming at first. But as I’ve come to realize, it’s actually a fantastic platform that makes collaboration and version control much easier. In this article, I want to share my personal experience and guide fellow beginners who are just stepping into the world of GitHub. Whether you’re working on your own small projects or aiming to contribute to open-source code, this guide will help you get started and make sense of GitHub’s basic features.

What is GitHub?

Before we dive into the steps, let me quickly explain what GitHub is, in the simplest terms. GitHub is like a cloud storage for your code. It helps developers manage and track changes in their projects, whether they are working alone or with a team. It also allows people to contribute to each other’s projects in an organized way. If you're a beginner, this might sound a bit complicated, but once you start using it, everything will make sense.

GitHub is built on top of Git, which is a version control system. Git keeps track of all the changes you make to your files so you can easily go back to previous versions if something goes wrong. GitHub makes it easier to use Git, especially when working with others.

How to Get Started on GitHub

Step 1: Sign Up for GitHub

The first step is to create your GitHub account. It's free and simple:

  1. Visit GitHub.com and click on Sign up.
  2. Choose a username, add your email, and set a password.
  3. After that, you’ll be guided through a short setup process where you can choose your preferences.

Step 2: Install Git

Before using GitHub from your computer, you need to install Git. Think of Git as the tool that lets you manage your code locally (on your system) and GitHub as the place where you store that code online.

You can download Git from git-scm.com. After installing, check if it’s working by opening your terminal (Command Prompt for Windows users) and typing:

git --version
Enter fullscreen mode Exit fullscreen mode

This should show you the version of Git installed.

Step 3: Configure Git

Once Git is installed, you need to tell it who you are. This is necessary because Git will use this information to track your changes. Just run these two commands in your terminal, replacing "Your Name" and your.email@example.com with your actual details:

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

This way, whenever you make changes to your project, Git will remember you as the author.

Step 4: Create Your First Repository

A repository (often shortened to "repo") is where your project files are stored. You can think of it as a folder that contains your project. Here’s how to create your first one:

  1. Go to your GitHub account.
  2. Click on the Repositories tab.
  3. Click the green New button to create a new repository.
  4. Give it a name (for example, "my-first-repo") and choose whether to make it public or private.
  5. Click Create repository.

Now you’ve got your own project space on GitHub!

Step 5: Work Locally and Connect to GitHub

Once your repository is created on GitHub, it’s time to link it to your local system. Here’s how you can do it:

  1. On your terminal, navigate to the folder where you want your project to live by using the cd command.
  2. Initialize a new Git repository locally by running:
   git init
Enter fullscreen mode Exit fullscreen mode
  1. Link this local repository to the one you created on GitHub by adding a remote:
   git remote add origin https://github.com/your-username/repository-name.git
Enter fullscreen mode Exit fullscreen mode

This connects your local project folder with the GitHub repository.

Basic GitHub Commands

Now that you’ve set up everything, let’s look at some basic commands you’ll use often.

Adding Files to Your Repository

To add files to your project, you just place them in your project folder. Then, run this command to tell Git you want to track the changes:

git add .
Enter fullscreen mode Exit fullscreen mode

The . means you're adding all the files in the folder. If you only want to add specific files, replace . with the file name.

Committing Changes

Once you've added your files, the next step is to save these changes in the form of a commit. Think of a commit like a checkpoint for your project. You can create a commit with this command:

git commit -m "Your commit message"
Enter fullscreen mode Exit fullscreen mode

Always make your commit message descriptive. It will help you and others understand what changes were made.

Pushing Your Changes to GitHub

To send your changes from your computer to GitHub, use the push command:

git push origin main
Enter fullscreen mode Exit fullscreen mode

This command uploads all your changes to the main branch of your GitHub repository.

Pulling Changes from GitHub

If you’re working with others, or if you’ve made changes to your project from another computer, you’ll want to keep your local copy up to date. To do this, use the pull command:

git pull origin main
Enter fullscreen mode Exit fullscreen mode

This will download any changes from GitHub to your local machine.

Contributing to Other Projects

Forking a Repository

One of the most exciting things about GitHub is the ability to contribute to open-source projects. But you don't directly make changes to other people's repositories. Instead, you create a copy (or "fork") of the repository, make changes in your copy, and then suggest those changes to the original owner.

  1. Go to the project you want to contribute to.
  2. Click the Fork button at the top right.
  3. This creates a copy of the repository under your GitHub account.

Pull Requests

Once you've made changes to your forked project, you can create a Pull Request (PR) to suggest these changes to the original project.

  1. Push your changes to your GitHub fork.
  2. Go to the original project repository.
  3. Click New Pull Request and describe the changes you’ve made.

The project owner can then review your changes and decide to merge them into their project.

Hosting Your Own Projects

A cool feature on GitHub is GitHub Pages, which allows you to host websites directly from your repositories. If you’re working on a web development project, you can host it online in just a few clicks.

  1. Go to your repository’s settings.
  2. Scroll down to GitHub Pages and select the branch you want to use for your website.
  3. Your site will be live at https://your-username.github.io/repository-name.

Final Thoughts

As a student, learning GitHub was like opening a door to a bigger world. The platform not only helps in managing your code but also connects you with a larger developer community. Start small, practice regularly, and soon you’ll feel at home with GitHub.

Whether you’re using GitHub to store personal projects, collaborate with friends, or contribute to open-source communities, it’s a tool that will be with you throughout your coding journey.

Happy coding, and don’t forget to push your changes often!

Top comments (0)