Version Control Basics
(Git Overview)



What is Version Control?

Version control is a system that records changes to files over time so that you can recall specific versions later. It is essential for collaborative software development and also extremely useful for solo developers to track and manage changes.

Why Use Version Control?

Types of Version Control

Why Git?

Git is the most popular distributed version control system. It is fast, reliable, and widely used by developers worldwide. Git enables local development, branching, merging, and collaboration on remote repositories.

Installing Git

# For Windows/macOS/Linux
# Visit https://git-scm.com/ and download the appropriate installer

Basic Git Workflow

  1. Initialize a repository
  2. Add files to staging
  3. Commit changes
  4. View commit history

Step-by-Step Git Example

1. Initialize a Git repository

git init

This creates a hidden .git folder in your current directory, marking it as a Git repository.

2. Add files to the staging area

git add myfile.txt

This stages the specified file to be committed.

3. Commit the changes

git commit -m "Initial commit with myfile.txt"

This records the snapshot of your staged files.

4. View the commit history

git log

Output:

commit 6a1f9d9c7a...
Author: Your Name
Date:   Fri May 9 10:00:00 2025 +0530

    Initial commit with myfile.txt

Understanding the Workflow

START
  INIT project with 'git init'
  CREATE or MODIFY files
  STAGE files with 'git add'
  COMMIT with message
  REPEAT on changes
END

Common Beginner Questions

Q: What happens if I change a file but forget to commit?

A: The change stays in your working directory. You can use git status to see uncommitted changes.

Q: Can I undo a mistake?

A: Yes. Git provides commands like git checkout, git reset, and git revert to manage changes.

Q: Do I need an internet connection to use Git?

A: No, Git works locally. You only need internet when working with remote repositories like GitHub.

Using Branches

Branches help you work on new features without affecting the main codebase.

git branch feature-x
git checkout feature-x

Merging Changes

Once your work is complete, merge it into the main branch.

git checkout main
git merge feature-x

Working with Remote Repositories

git remote add origin https://github.com/your/repo.git
git push -u origin main

This pushes your local commits to a remote repository for backup or collaboration.

Summary

Mini Practice Project

Create a simple pseudocode project (e.g., a calculator), track changes using Git as you evolve your logic from basic operations to advanced ones like recursion.

Tip: Always commit small logical changes with meaningful messages. This makes history cleaner and easier to navigate.



Welcome to ProgramGuru

Sign up to start your journey with us

Support ProgramGuru.org

Mention your name, and programguru.org in the message. Your name shall be displayed in the sponsers list.

PayPal

UPI

PhonePe QR

MALLIKARJUNA M