← Back to list

Git & GitHub for Beginners: Complete Guide

Master Version Control — Step-by-Step Tutorial

Harikrishnan · 2025-11-25 17:40 · 58 claps · 7.4 min read
#git #github #version-control-system #cybersecurity #git-tutorial
Open on Medium ↗
Wiki topics: 🔒 · Cybersecurity 🔓 · Open Source

Git & GitHub for Beginners: Complete Guide

Master Version Control — Step-by-Step Tutorial

What is Git?

Git is a free, open-source distributed version control system designed to help you manage changes to files — especially code — across your computer and team collaborations. Think of it as a time machine for your project. It stores a complete history of every change made, allowing you to track “who changed what and when” and roll back mistakes if needed.

Why Use Git?

  • Speed & Reliability: Fast operations with data integrity built-in
  • Collaboration: Multiple people can work on the same project simultaneously
  • Accountability: Track exactly who made changes and when
  • Safety Net: Revert to previous versions if something breaks
  • Flexibility: Work offline, sync when ready

Git workflow

Git workflow

What Is Version Control?

Version control is a system that tracks changes to your files especially code, so you can see what you changed, when you changed it, and who changed it.

Think of it like a time machine for your project.

Whenever you update your files, version control:

  • Saves a snapshot (called a commit)
  • Stores only the changes
  • Lets you go back to any previous version
  • Helps multiple people work together without messing up each other’s code

How Version Control Helps

1. Keeps Every Version Safe

If your new code breaks something → just restore an older version.

2. Makes Collaboration Easy

Multiple developers can work on the same project without conflicts.

3. Shows Who Changed What

Great for teams and reviewing code.

4. Protects Your Work

Even if something goes wrong in your local machine, the history in Git or GitHub saves you.

1.Getting Started: Three Main Stages

Before we dive deeper, understand the core workflow:

  1. Create a file on your local system
  2. Add it to Git tracking with git add
  3. Commit it with a message using git commit

2.Step-by-Step: Setting Up Git

1. Verify Git Installation

git --version

Shows the installed Git version on your system.

2. Configure Your Identity

Git needs to know who you are before making commits:

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

3. Verify Your Configuration

git config --global --list

Displays all your Git settings, including name and email.

3.Creating Your First Local Repository

Step 1: Initialize Git

Navigate to your project folder and run:

git init

This creates a hidden .git folder that tracks all your changes.

Note: By default, this creates a master branch. To use main instead (modern standard):

git init -b main

Step 2: Check Git Status

git status

This shows the current state of your repository. Initially, you’ll see untracked files.

Step 3: Add Files to Staging Area

To track a specific file:

git add filename.txt

To track all files at once:

git add .

The dot (.) means "all files in this directory."

Step 4: Commit Your Changes

Committing is like saving a checkpoint in your project:

git commit -m "Your descriptive message here"

The -m flag lets you add a message describing what changed. Good messages help you and your team understand the history.

Step 5: Verify Your Commit

git log

This displays your commit history with:

  • Unique commit ID (hash)
  • Author information
  • Commit date
  • Commit message

4.Understanding Git Concepts

The Three Areas of Git

  1. Working Directory: Your actual files on disk
  2. Staging Area: Files marked for the next commit (git add)
  3. Repository: Committed changes stored in .git folder

Commit Hashes (Why They Matter)

Each commit gets a unique identifier — a 40-character SHA-1 hash (though Git typically shows the first 7 characters). This ensures:

  • No two commits are identical
  • Files can’t be altered without detection
  • You can always reference a specific point in history

5.Working With Changes

View Changes in Files

See what’s changed but not yet staged:

git diff

See what’s changed in staged files:

git diff --staged

Shortcut: Commit Without Staging

If you’ve already committed a file before, skip the add step:

git commit -a -m "Your message"

6.Removing Files

Remove from Staging (Keep Locally)

git rm --cached filename.txt

Useful for removing sensitive files (credentials, API keys) before pushing to GitHub.

Remove Completely

git rm filename.txt

Deletes from both staging and your local system.

Important: Always commit after removing files:

git commit -m "Remove sensitive files"

Introduction to GitHub

What is GitHub?

GitHub is a cloud-based platform where you store your Git repositories online. It provides:

  • Online code storage
  • Collaboration tools
  • Version tracking
  • Issue management
  • Open-source contribution opportunities

Why Use GitHub?

  • Store your code safely in the cloud
  • Collaborate with teammates across locations
  • Track every change with full history
  • Share projects publicly or keep them private
  • Showcase your work in a portfolio

Pushing Your Project to GitHub

Step 1: Create a account in github

  1. Go to github.com
  2. Create an account with your email id

Step 2: Create a Repository on GitHub

  1. Go to your profile
  2. Click “New Repository”
  3. Name it (e.g., “my-first-project”)
  4. Choose public or private
  5. Click “Create Repository”

Step 3: Connect Local Repository to GitHub

GitHub will show you commands to run. Follow this workflow in your project folder:

git init
git add README.md
git commit -m "Initial commit"
git branch -M main
git remote add origin https://github.com/your-username/your-repo.git
git push -u origin main

Understanding These Commands

  • git init: Initialize local repository
  • git add: Stage your files
  • git commit: Save changes locally
  • git branch -M main: Rename branch to "main"
  • git remote add origin [URL]: Connect to GitHub (origin = nickname for your repo URL)
  • git push -u origin main: Push commits to GitHub (-u = stands for set upstream remember this connection)

Step 3: Subsequent Updates

After your first push, updating GitHub is simple:

git add .
git commit -m "Description of changes"
git push origin main

Using Tags to Mark Versions

What is a Tag?

A tag is a bookmark on a specific commit. It helps you mark:

  • Stable releases (v1.0, v2.0)
  • Milestones
  • Important checkpoints

Tags never change — they permanently attach to that commit.

Tag Commands

Create a tag:

git tag v1.0

Create a tag with a description:

git tag -a v1.0 -m "First stable release"

View all tags:

git tag

Delete a tag (local):

git tag -d v1.0

Delete a tag from GitHub:

git push origin --delete tag v1.0

Why Tags Matter

When someone visits your GitHub repo, they can easily see all versions and download the exact one they need — critical for project stability and user trust.

Cloning a Repository

What is Clone?

Cloning downloads an entire repository from GitHub to your local system.

git clone https://github.com/username/repository.git

This includes:

  • All files and folders
  • Complete commit history
  • All branch

Working With Branches

What are Branches?

Branches let you work on features independently without affecting the main code. Think of it as creating an experimental copy of your project.

Create a New Branch

git checkout -b branch-name

Or the modern way:

git switch -c branch-name

Switch Between Branches

git switch branch-name

View All Branches

git branch

Delete a Branch

git branch -d branch-nam

Working on a Branch

Make changes, then commit them:

git add .
git commit -m "Added new feature"
git push origin branch-name

Merging Branches

What is Merge?

Merging combines changes from one branch into another. Typical workflow:

  1. Create experimental branch
  2. Make and test changes
  3. Switch back to main
  4. Merge the experimental branch to main branch

Merge Steps

Switch to main branch:

git switch main

Merge your experimental branch:

git merge branch-name

Push the merged changes to GitHub:

git push origin main

Real-World Collaboration Example

Imagine a team of three developers on a project:

  1. Developer A commits: “Added user authentication”
  2. Developer B commits: “Fixed login bug”
  3. Developer C commits: “Improved password validation”

Each commit message tells the story of who did what. This makes collaboration smooth and accountability clear. If something breaks, you can trace exactly which commit caused it and even revert if needed.

Quick Reference: Essential Commands

Commands — — — — — — — — — — — — — — — — — — — — — — — -— — — — — — — git init — — — — — — — — — — — — — — —-→Initialize a repository git add . — — — — — — — — — — — — —— -→Stage all files git commit -m “message” — — — — — — →Commit changes git push origin main — — — — — — — — — →Push to GitHub git pull origin main — — — — — — — — —-→Get latest from GitHub git clone [URL] — — — — — — — — — — — —→Download repository git branch — — — — — — — — — — — — — — →View branches git switch -c branch-name — — — — — — →Create and switch branch git merge branch-name — — — — — — —-→Merge branch into current git log — — — — — — — — — — — — — — — — →View commit history git tag v1.0 — — — — — — — — — — — — — —→Create a version tag

Key Takeaways

  1. Git tracks changes: Every modification is recorded with history
  2. Commits are checkpoints: Create meaningful commits to track progress
  3. GitHub enables collaboration: Share code and work with teams globally
  4. Branches enable experimentation: Test features safely without affecting main code
  5. Tags mark releases: Help users find stable versions
  6. Always write good messages: Help your future self and teammates understand changes

Final Thoughts

Git might seem overwhelming at first, but it becomes second nature with practice. Start with the basics: init, add, commit, and push. Once comfortable, explore branches, merging, and collaboration features.

The key is consistent practice. Create projects, make commits, and push to GitHub regularly. You’re not just learning a tool — you’re adopting a professional development workflow used by millions of developers worldwide.

Happy coding!🙌


메타데이터
post_id
2db4068d2d33
slug
git-github-for-beginners-complete-guide-2db4068d2d33
url
https://medium.com/@LEARNWITHHARI/git-github-for-beginners-complete-guide-2db4068d2d33
canonical_url
https://medium.com/@LEARNWITHHARI/git-github-for-beginners-complete-guide-2db4068d2d33
author_url
https://medium.com/@LEARNWITHHARI
status
ok
fetched_at
2026-08-06 20:06:25