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)
Feature | Git | GitHub |
---|---|---|
Type | Version Control Tool | Cloud Hosting Platform |
Works Offline? | Yes | No (requires internet access) |
Created By | Linus Torvalds (2005) | GitHub, Inc. (2008, now owned by Microsoft) |
Purpose | Track code changes | Collaborate 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:
- Visit the official Git website: https://git-scm.com
- Click on Download for Windows.
- Run the installer and keep the default settings (unless you’re an advanced user).
- After installation, open the Git Bash application.
🔸 For macOS:
- Open Terminal and run:
brew install git
(You’ll need Homebrew installed)
🔸 For Linux:
- Use your distro’s package manager. For Ubuntu/Debian:
sudo apt update
sudo apt install git
✅ To check if Git is installed:
git --version
Step 2: Configure Git (One-Time Setup)
After installing Git, set your name and email:
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:
git config --list
Step 3: Create a GitHub Account
- Go to https://github.com
- Click Sign up.
- Choose a username, enter your email, and set a password.
- 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.
Step 4: (Optional but Recommended) Generate SSH Key
To securely connect your computer to GitHub:
1. Generate an SSH key:
ssh-keygen -t ed25519 -C "your_email@example.com"
2. Copy the key:
cat ~/.ssh/id_ed25519.pub
3. Go to GitHub → Settings → SSH and GPG keys → New SSH key → Paste your key and save.
✅ You’re now ready to start using Git and GitHub together.
👉 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
Command | Description |
---|---|
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 --list | View your Git configuration |
📁 Repository Setup
Command | Description |
---|---|
git init | Initialize a new Git repository |
git clone [url] | Copy an existing repository from GitHub |
git status | Check changes in your project |
📄 Staging & Committing
Command | Description |
---|---|
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 log | View commit history |
🔄 Branching & Merging
Command | Description |
---|---|
git branch | List 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
Command | Description |
---|---|
git remote -v | Show remote repository links |
git push origin [branch] | Upload your changes to GitHub |
git pull origin [branch] | Download latest changes from GitHub |
🧹 Undoing Mistakes
Command | Description |
---|---|
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:
mkdir my-first-git-project
cd my-first-git-project
🛠️ Step 2: Initialize Git
This makes your folder a Git repository:
git init
You’ll see:
Initialized empty Git repository in /your/path/my-first-git-project/.git/
📄 Step 3: Create a File
Now add your first file:
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:
git status
Then stage the file:
git add README.md
💬 Step 5: Commit Your Changes
Save your staged changes with a meaningful message:
git commit -m "Initial commit with README"
🐙 Step 6: Create a GitHub Repository
- Go to https://github.com
- Click New > Name your repo (e.g.,
my-first-git-project
) - Do not initialize with a README (you already have one)
🔗 Step 7: Link Local Repo to GitHub
Copy the repository link and run:
git remote add origin https://github.com/yourusername/my-first-git-project.git
To verify:
git remote -v
☁️ Step 8: Push to GitHub
Now upload your local code to GitHub:
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.