Simple and Powerful Git and GitHub Guide for Beginners 2025

Git and GitHub Commands Guide for Beginners Step-by-Step with Examples

Git and GitHub Introduction

Git and GitHub are version control systems.
It helps you track changes in your files and work on different versions, and we can roll it back if required.
It remembers every change you make, who made it, when they made it, and why.

What are Git and GitHub?

GitHub is a website where you can store your Git projects online.
You can share code, work with Team, and keep a backup of your work.

GitHub is built on Git but offers more powerful features such as:

  • Securely hosting your code online
  • Easy teamwork without overwriting each other’s work
  • Reviewing and approving changes before adding them to the main code (pull requests)
  • Managing tasks, issues, and project progress in one place
  • Sharing code publicly so others can use and contribute (open source)

Note: “Open source” means your code is free for anyone to see, use, and improve.

Git and GitHub How It Works

In Git, work moves through 4 main stages:

Working Directory → Staging Area → Local Repository → Remote Repository

Git and GitHub Workflow

StagesMeaning
Working DirectoryWhere you write/edit code (not yet tracked in Git).
Staging AreaChanges are ready to commit.
Local RepositoryYour committed history is stored on your computer.
Remote RepositoryStored on GitHub or any remote server.
Understanding the Linux Kernel 2024

ALSO READ:

Click here to go to the GitHub repos link

Common Git and GitHub Commands (With Examples)

List of the most used Git commands and when to use them.

# 1. Clone a Repository Download a project from GitHub to your local machine.
git clone <url>

# 2. See Changes

git diff

# Shows changes between Working Directory ↔ Staging Area.

git diff HEAD


# Shows changes between Working Directory + Staging Area ↔ Last Commit.

git diff --staged   # same as --cached

# Shows changes between Staging Area ↔ Last Commit.

git diff <commit-or-branch>

# Compares your current work with another commit/branch.

git diff --cached <commit-or-branch>

# 3. Moves changes from Working Directory → Staging Area.

git add <file>
git add .  # add all files 

# 4. Commit Changes

git commit -m "Message"

# Stages and commits all tracked files in one step (skips git add).

git commit -a -m "Message" 

# 5. Push to Remote

git push origin main


# 6. Gets the latest changes from remote without merging them into your branch.

git fetch

# 7. Combines another branch’s changes into your current branch.

git merge


# 8. Fetch + Merge in one step (gets remote changes and merges them into your branch).

git pull

# 9. Shows commit history in detail.

git log

# Shows commit history in short form.

git log --oneline

# 10. Make a new branch and change to new branch

git checkout -b feature-branch

Thank you.

Leave a Comment

Index