Git and GitHub for Beginners: A Comprehensive Step-by-Step Guide
Florence Enenmo
Posted on August 3, 2024
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.
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.
Leave the rest at default.
Click Create Repository.
Created Repository
Step 2: Setting Up Git
To start using Git, install it on your machine and configure some basic settings.
Install Git
- Windows: Download the installer from Git for Windows and follow the instructions.
- Mac: Install Git using Homebrew with the command brew install git.
- 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
- Type git config --global user.email "your.email@example.com" and click enter on your device
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.
- This takes you to Visual Studio Code.
Click on the icon to create a file.
Name the file index.html
- Paste your HTML code into it
Go to Terminal
Click on the three dots at the top
Click on Terminal, then New Terminal
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 .
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
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
Copy the URL
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
Type git push origin master
Click enter
If you are pushing for the first time, you will be taken to GitHub sign-in and authorization.
Go to GitHub
See recent push
To Create a README file
Go to your Visual Code
Click on New File
Type readme.md
Type a message
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.
Type git add . to add the file
Type git commit -m "adding readme.md"
Click **enter
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
To edit, click on the edit icon
After editing your text, click on Commit Changes
Extended Description is optional
Click on Commit Changes
To see the changes made on your file, to Visual Code terminal
Type git pull origin master
Click enter
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.
Posted on August 3, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.