DEV Community

Cover image for Git and GitHub for Beginners: A Comprehensive Step-by-Step Guide
Florence Enenmo
Florence Enenmo

Posted on • Updated on

Git and GitHub for Beginners: A Comprehensive Step-by-Step Guide

Introduction

Git and GitHub have become essential tools for developers, enabling efficient version control, collaboration, and code management. Whether you are a seasoned developer or a beginner, understanding these tools is crucial. This blog will guide you through setting up Git, creating a repository, making commits, pushing changes, pulling updates, and more.

What is Git?

Git is a distributed version control system designed to handle everything from small to very large projects with speed and efficiency. It allows multiple developers to work on a project simultaneously without interfering with each other's work.

What is GitHub?

GitHub is a web-based platform that uses Git for version control. It offers a graphical interface, collaboration features, code reviews, and more. GitHub hosts millions of repositories, making it a hub for developers to share and collaborate on projects.

Step 1: Creating a Repository

A repository (repo) is a storage space where your project lives. You can create a repo locally on your machine or remotely on GitHub.

Create a Remote Repository on GitHub

  • Go to GitHub and log in. Click the + icon in the top right corner and select New Repository.

Image description

Fill in the repository name and description, choose visibility (public
or private), and add a README file. With a README file, you can add documentation about your project.

Image description

Leave the rest at default.
Click Create Repository.

Image description

Created Repository

Image description

Step 2: Setting Up Git

To start using Git, install it on your machine and configure some basic settings.

Install Git

  1. Windows: Download the installer from Git for Windows and follow the instructions.
  2. Mac: Install Git using Homebrew with the command brew install git.
  3. Linux: Use your package manager, e.g., sudo apt-get install git for Debian-based distributions.

Configure Git

  • After installation, to verify that Git is installed correctly, type **git --version* and click enter on your device.

  • Configure your username and email. This information will be associated with your commits.

On Git Bash

  • Type git config --global user.name "Your Name", and click enter on your device.

Your Name should be your GitHub username

your.email@example.com should your GitHub log in email

  • Type mkdir GitLab and click enter on your device. This helps you create a folder. (Check to confirm the folder is created in your file manager)

mkdir stands for make directory. You can also use another name of your choice in place of GitLab

  • Type in cd GitLab and click enter on your device

cd means change directory

  • Type in git init and click enter on your device
    This helps you create a local repository.

  • To go to Visual Studio Code, type in code . and click enter on your device
    You should have already downloaded Visual Studio Code* on your device.

Image description

  • This takes you to Visual Studio Code.

Image description

  • Click on the icon to create a file.

  • Name the file index.html

Image description

  • Paste your HTML code into it

Image description

Go to Terminal

  • Click on the three dots at the top

  • Click on Terminal, then New Terminal

Image description

  • To add all your files, type git add ..

  • Click enter on your device.

You can type git status and click enter to see all the information.

Your file name will appear because you have already added your file by earlier typing git add .

Image description

Making a Commit

A commit includes a snapshot of your project files and a message describing the changes.

Type git commit -m "adding index.html"
Click enter

Image description

Step 3: Link Local and Remote Repositories

Link your local repository to the remote one on GitHub:

Go to your GitHub account.
Click on Code

Image description

Copy the URL

Image description

Go to your Visual Code
Type git remote add origin, and paste the URL copied from GitHub

git remote add origin https://github.com/yourusername/your-repo-name.git. Click enter

Image description

Type git push origin master
Click enter

Image description

If you are pushing for the first time, you will be taken to GitHub sign-in and authorization.

Image description

Image description

Go to GitHub
See recent push

Image description

To Create a README file
Go to your Visual Code
Click on New File
Type readme.md

Image description

Type a message

Image description

Click ctrl S to save

On the terminal, if you type git status and click enter, it shows you have a new file that has not yet been added.

Image description

Type git add . to add the file
Type git commit -m "adding readme.md"
Click **enter

Image description

Type git push origin master
Click enter

To check the readme file, go to your GitHub account, refresh, and click on readme.md to see the message earlier typed when you created the readme.md file

Image description

Image description

To edit, click on the edit icon

Image description

After editing your text, click on Commit Changes

Image description

Extended Description is optional
Click on Commit Changes

Image description

To see the changes made on your file, to Visual Code terminal
Type git pull origin master
Click enter

Image description

Git and GitHub are powerful tools for managing code and collaborating with others. By following this guide, you should be able to set up Git, create repositories, make commits, and perform essential Git operations.

Top comments (0)