</>
Skip to content
Git lessons (2/44)

Git — Introduction

What is Git?

Git is a distributed version control system. It tracks changes to files over time, lets you recall specific versions later, and enables multiple people to work on the same project without overwriting each other's work.

Created by Linus Torvalds in 2005 (to develop Linux), Git is now the most widely used version control system in the world.

Why Version Control?

Imagine writing a research paper without saving versions:

  • "report_final.doc"
  • "report_final_v2.doc"
  • "report_final_ACTUALLYfinal.doc"
  • "report_final_send_to_professor.doc"

This is chaos. Git solves this elegantly:

git log
# Shows every version ever saved, with dates, messages, and authors

What Git Tracks

  • File changes — what was added, removed, or modified
  • Who made changes — author name and email
  • When changes happened — timestamps
  • Why changes were made — commit messages

The Three States

Git has three main states for your files:

StateDescription
Working DirectoryYour actual files on disk
StagedChanges marked for the next commit
CommittedChanges saved to the Git history
# See the status
git status

Basic Workflow

# 1. Make changes to files
echo "Hello, World!" > readme.txt

# 2. Stage changes
git add readme.txt

# 3. Commit changes
git commit -m "Add readme file"

# 4. View history
git log --oneline

The Repository

A Git repository (.git folder) contains the entire history of your project:

my-project/
├── .git/          ← Git repository (don't touch!)
├── src/
│   └── app.js
├── index.html
└── package.json

The .git folder is hidden by default. It stores:

  • All committed snapshots
  • Branch and tag information
  • Configuration settings
  • Remote repository URLs

Local vs Remote

  • Local repository — on your computer
  • Remote repository — on a server (GitHub, GitLab, etc.)
# Clone a remote repo
git clone https://github.com/user/repo.git

# Check remote
git remote -v

Your First Repository

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

# Initialize Git
git init

# Create a file
echo "# My Project" > README.md

# Stage and commit
git add README.md
git commit -m "Initial commit"

# Check the log
git log --oneline
# abc1234 (HEAD -> main) Initial commit

Common Commands

CommandPurpose
git initCreate a new repository
git clone <url>Copy a remote repository
git statusShow working directory status
git add <file>Stage a file
git commit -m "msg"Save staged changes
git logShow commit history
git pushUpload to remote
git pullDownload from remote

Git vs Other Tools

FeatureGitDropboxGoogle Drive
Version historyFullLimitedLimited
BranchingYesNoNo
Offline workYesNoPartial
SpeedVery fastSlowSlow
Merge conflict resolutionYesNoNo

Common Mistakes

  1. Not committing often — commit early, commit often
  2. Bad commit messages — "fixed stuff" tells you nothing
  3. Committing secrets — never commit passwords, API keys
  4. Not using .gitignore — don't track build files, dependencies

Best Practices

  • Commit early and often
  • Write clear, descriptive commit messages
  • Use .gitignore to exclude unnecessary files
  • Pull before you push
  • Create branches for new features
  • Never force-push to shared branches

Mini Practice

  1. Create a new repository with git init
  2. Add a file and make your first commit
  3. Make changes and commit again
  4. View the commit log
  5. Check the status between each step

Up Next

Next: Getting Started →

Related Topics

Frequently Asked Questions about Introduction

What is Introduction in Git?

Introduction is a fundamental concept in Git. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Introduction?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Introduction.

Why is Introduction important in Git?

Introduction is essential for Git development. Understanding this concept will help you write better code and solve real-world problems more effectively.