💡 Ask Tutor

Git & GitHub

Welcome to “Git & GitHub”, your go-to guide for mastering the most powerful version control system used in the software industry today. Whether you’re a student just starting out or a professional looking to improve your workflow, this book will walk you through everything from the basics of Git to advanced GitHub automation techniques.

In today’s collaborative development world, understanding Git (a distributed version control system) and GitHub (a platform to host Git repositories) is no longer optional — it’s essential. Whether you’re building solo projects, contributing to open-source, or working in a team, GitHub is where code collaboration truly happens.

This learn guide is designed to be hands-on and beginner-friendly. You don’t need prior experience with version control or GitHub. We’ll start by installing Git and configuring your GitHub account. Then, we’ll move step-by-step through real-world scenarios including commits, branches, pull requests, merge conflicts, and even CI/CD pipelines with GitHub Actions.

Here’s what you’ll learn:

  • Git basics and core commands
  • Creating and managing repositories
  • Collaborating using forks, pull requests, and branches
  • Handling merge conflicts and keeping your code organized
  • Contributing to open-source projects
  • Automating workflows using GitHub Actions
  • GitHub interview questions to help you prepare for job roles

By the end of this guide, you’ll be confident using Git and GitHub in any project — academic or professional.

Let’s begin your version control journey the smart way.

What is Git? What is GitHub?

What is Git?

Git is a distributed version control system that lets you track changes in your code over time. It allows multiple developers to work on the same project without overwriting each other’s work. With Git, you can:

  • Save versions of your code (called commits)
  • Revert to earlier versions if needed
  • Work with branches to test features without affecting the main code
  • Merge code from different contributors in a clean and organized way

Git runs locally on your computer and does not require an internet connection to manage your code history.

💡 Fun fact: Git was created in 2005 by Linus Torvalds, the creator of Linux.

What is GitHub?

GitHub is a web-based platform that hosts Git repositories online. It adds collaboration features on top of Git, such as:

  • Pull Requests (for proposing changes)
  • Issues (for tracking bugs or tasks)
  • Project Boards (like Kanban)
  • Wikis and documentation
  • GitHub Actions for automation

Think of GitHub as a social network for developers. You can share your code, contribute to other people’s projects, and showcase your work to the world.

✅ Git is the tool, and GitHub is the platform built around that tool.

Git vs GitHub (Quick Comparison Table)

FeatureGitGitHub
TypeVersion Control ToolCloud Hosting Platform
Works Offline?YesNo (requires internet access)
Created ByLinus Torvalds (2005)GitHub, Inc. (2008, now owned by Microsoft)
PurposeTrack code changesCollaborate and share Git repositories

Installing Git and Configuring GitHub

To start using Git and GitHub, you’ll need to install Git on your local machine and create a GitHub account.

Step 1: Install Git on Your Computer

🔸 For Windows:

  1. Visit the official Git website: https://git-scm.com
  2. Click on Download for Windows.
  3. Run the installer and keep the default settings (unless you’re an advanced user).
  4. After installation, open the Git Bash application.

🔸 For macOS:

  • Open Terminal and run:
Bash
brew install git

(You’ll need Homebrew installed)

🔸 For Linux:

  • Use your distro’s package manager. For Ubuntu/Debian:
Bash
sudo apt update
sudo apt install git

✅ To check if Git is installed:

Bash
git --version

Step 2: Configure Git (One-Time Setup)

After installing Git, set your name and email:

Bash
git config --global user.name "Your Name"
git config --global user.email "you@example.com"

This info is used to identify you as the author of commits.

To check your configuration:

Bash
git config --list

Step 3: Create a GitHub Account

  1. Go to https://github.com
  2. Click Sign up.
  3. Choose a username, enter your email, and set a password.
  4. Verify your account via email.

Once logged in, you’ll land on your GitHub Dashboard where you can create or view repositories, follow other developers, and manage your projects.

To securely connect your computer to GitHub:

1. Generate an SSH key:

Bash
ssh-keygen -t ed25519 -C "your_email@example.com"

2. Copy the key:

Bash
cat ~/.ssh/id_ed25519.pub

3. Go to GitHub → Settings → SSH and GPG keysNew SSH key → Paste your key and save.

✅ You’re now ready to start using Git and GitHub together.


💡 Need help understanding this topic?
👉 Ask our Educational Tutor now!

Git Commands Cheat Sheet

This chapter gives you a quick reference to the most commonly used Git commands — with simple examples and use cases.

💡 Tip: You’ll use many of these commands daily when working on real projects.

🔹 Configuration

CommandDescription
git config --global user.name "Your Name"Set your Git username
git config --global user.email "you@example.com"Set your Git email
git config --listView your Git configuration

📁 Repository Setup

CommandDescription
git initInitialize a new Git repository
git clone [url]Copy an existing repository from GitHub
git statusCheck changes in your project

📄 Staging & Committing

CommandDescription
git add .Add all changes to staging area
git add [file]Add specific file to staging
git commit -m "Your message"Save your changes with a message
git logView commit history

🔄 Branching & Merging

CommandDescription
git branchList branches
git branch [name]Create a new branch
git checkout [name]Switch to a branch
git merge [branch]Merge another branch into current one

🔼 Pushing & Pulling

CommandDescription
git remote -vShow remote repository links
git push origin [branch]Upload your changes to GitHub
git pull origin [branch]Download latest changes from GitHub

🧹 Undoing Mistakes

CommandDescription
git reset [file]Unstage a file
git checkout -- [file]Discard changes to a file
git revert [commit]Revert a commit safely
git reset --hard [commit]Dangerous: Reset to a specific commit and erase history

This cheat sheet will be your quick-access toolbox throughout your Git journey.

First Git Project — Initialize, Add, Commit, Push

Now that Git is installed and configured, let’s create your first real Git project and push it to GitHub. This is the basic workflow you’ll follow for almost every project.

📁 Step 1: Create a Project Folder

Create a new folder on your desktop or anywhere you prefer:

Bash
mkdir my-first-git-project
cd my-first-git-project

🛠️ Step 2: Initialize Git

This makes your folder a Git repository:

Bash
git init

You’ll see:

SQL
Initialized empty Git repository in /your/path/my-first-git-project/.git/

📄 Step 3: Create a File

Now add your first file:

Bash
echo "# Hello Git!" > README.md

You can also use any code editor to create/edit files in this folder.

📌 Step 4: Add File to Staging Area

Check the status of your repo:

Bash
git status

Then stage the file:

Bash
git add README.md

💬 Step 5: Commit Your Changes

Save your staged changes with a meaningful message:

Bash
git commit -m "Initial commit with README"

🐙 Step 6: Create a GitHub Repository

  1. Go to https://github.com
  2. Click New > Name your repo (e.g., my-first-git-project)
  3. Do not initialize with a README (you already have one)

Copy the repository link and run:

Bash
git remote add origin https://github.com/yourusername/my-first-git-project.git

To verify:

Bash
git remote -v

☁️ Step 8: Push to GitHub

Now upload your local code to GitHub:

Bash
git push -u origin master

🔁 You might be prompted to log in — enter your GitHub credentials or use SSH if configured.

✅ Done!

Your project is now live on GitHub. 🎉
Visit your repo URL to see the README file you created.

📘 Next Topic

Branching and Merging in Git →