Skip to content

Git Tutorial for Beginners — Learn Git in 20 Minutes

DodaTech 2 min read

In this tutorial, you'll learn about Git Tutorial for Beginners. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.

What You'll Learn

Learn Git from scratch — install, configure, create repos, stage and commit changes, branch, merge, and push to GitHub. No prior Git knowledge needed.

Why It Matters

Git is the most widely used version control system. Every developer uses it daily. Understanding Git is non-negotiable for professional software development.

Real-World Use

Collaborating on a team project, reverting a buggy change, experimenting on a feature branch without breaking main, or deploying from a specific tag.

What is Git?

Git is a distributed version control system — it tracks changes to files and lets multiple people work on the same project without stepping on each other.

Without Git:
Code on Alice's laptop ≠ Code on Bob's laptop ≠ Code on server
"Can you send me the latest version?" "Wait, which one is latest?"

With Git:
All changes tracked. Everyone has the full history. Conflicts resolved explicitly.

Install Git

# Linux (Debian/Ubuntu)
sudo apt install git

# Linux (Fedora/RHEL)
sudo dnf install git

# macOS
brew install git

# Windows
# Download from https://git-scm.com or use winget:
winget install Git.Git

First-Time Setup

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

# Verify
git config --list

Your First Repository

# Create a new project
mkdir my-first-repo
cd my-first-repo

# Initialize Git
git init

# Create a file
echo "# Hello Git" > README.md

# Check status
git status

# Stage the file
git add README.md

# Commit
git commit -m "Initial commit: add README"

# Check log
git log

The Basic Workflow

Working Directory → Staging Area → Local Repository → Remote Repository
                        ↓                ↓                  ↓
                    git add          git commit         git push

Every file in Git has one of four states:

State Description
Untracked New file, Git doesn't track it yet
Modified Tracked file has been changed
Staged Changes marked for next commit
Committed Safely stored in local Repository

Branching

Branches let you work on features in isolation:

# Create a branch
git branch feature-login

# Switch to it
git checkout feature-login
# Or in one command:
git checkout -b feature-login

# Make changes
echo "login feature" > login.py
git add login.py
git commit -m "Add login feature"

# Switch back to main
git checkout main

# Merge the feature
git merge feature-login

# Delete the branch (cleanup)
git branch -d feature-login

Working with GitHub

# Create a repo on GitHub first, then:
git remote add origin https://github.com/yourusername/my-first-repo.git

# Push your code
git push -u origin main

# Later pushes (after -u is set):
git push

Clone an Existing Repo

git clone https://github.com/username/project.git
cd project

Undoing Changes

# Unstage a file (keep changes)
git reset HEAD file.txt

# Discard all local changes to a file
git checkout -- file.txt

# Undo last commit (keep changes)
git reset --soft HEAD~1

# Undo last commit (discard changes)
git reset --hard HEAD~1

Practice

  1. Create a repo, add 3 files, commit them
  2. Create a branch, make changes, merge it
  3. Push to GitHub
  4. Clone someone else's repo and make a change

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro