RESOURCES
What Is Git? Understanding Version Control — A Beginner’s Guide
Learn what Git is, how version control works, and why developers use it. Explore repositories, commits, branches, merging, GitHub, and essential Git commands.
Vyomanant Academy
Build these skills hands-on
Explore structured, practical technology programs from Vyomanant Academy.
Explore CoursesOn this page
What Is Git? Understanding Version Control
Introduction
Imagine you are building your first website.
You create a homepage, add a navigation menu, and design a contact form. Everything works correctly.
The next day, you make several changes to improve the design. Unfortunately, something breaks, and you cannot remember exactly which changes caused the problem.
You might wish you could return to yesterday's working version.
This is one of the problems Git helps solve.
Git allows developers to track changes, maintain a history of their work, experiment safely, and collaborate on software projects.
It is widely used in software development, cloud engineering, DevOps, and IT automation.
What Will You Learn?
In this beginner-friendly guide, you'll understand:
- Git: What it is and why developers use it.
- Version Control: How software changes are tracked.
- Repositories: Where Git manages project history.
- Commits: How developers save meaningful checkpoints.
- Branches: How developers work on changes independently.
- Merging: How separate development work is combined.
- Git vs GitHub: Why they are related but different.
- Essential Commands: How to begin using Git.
- Practical Workflow: How to manage a small project from start to finish.
No previous Git experience is required.
1. What Is Git?
Git is a free, open-source, distributed version control system used to track changes in files and coordinate work on projects.
It was originally created by Linus Torvalds in 2005 to support Linux kernel development.
In simple words:
Git helps you record changes to a project, review its history, and manage different versions of your work.
Git is especially useful for projects containing source code, configuration files, scripts, and documentation.
What Can You Do with Git?
Git allows you to:
- Track Changes: Record how project files change over time.
- Save Checkpoints: Create commits representing meaningful versions.
- Review History: See previous changes and their authors.
- Experiment Safely: Develop features using separate branches.
- Collaborate: Combine work from multiple contributors.
- Recover Earlier Work: Restore appropriate files or versions when needed.
A Simple Example
Imagine your website project develops through four stages.
| Version | Change |
|---|---|
| Version 1 | Created the homepage |
| Version 2 | Added navigation |
| Version 3 | Added a contact form |
| Version 4 | Improved mobile layout |
Git can record these changes as commits.
If the latest change introduces a problem, you can inspect the history, compare versions, and choose an appropriate way to undo the problematic change.
Key Point: Git is more than a file backup tool. It is a system for managing project changes and development history.
2. What Is Version Control?
Version control is the practice of recording and managing changes to files over time.
Without version control, people sometimes create multiple copies of the same project.
For example:
website/
website-final/
website-final-updated/
website-final-new/
website-final-really-final/
This approach quickly becomes confusing.
You may not know:
- Which folder contains the latest working version.
- What changed between versions.
- Who made a particular change.
- Which files should be kept.
- How to combine changes made by different people.
A version control system helps organize this history.
How Does Version Control Help?
Instead of creating a new project folder for every update, you can maintain a Git repository and record changes through commits.
For example:
Website Project
|
v
Commit A: Create homepage
|
v
Commit B: Add navigation
|
v
Commit C: Add contact form
|
v
Commit D: Improve mobile layout
Each commit identifies a particular recorded state of the project.
Types of Version Control Systems
Version control systems are commonly categorized as:
- Local Version Control: Tracks file versions on a local computer.
- Centralized Version Control: Uses a central server to manage the primary repository history.
- Distributed Version Control: Allows each clone to contain a local copy of the repository's history.
Git is a distributed version control system.
This means developers can create commits and inspect history locally without needing a continuous connection to a central server.
Remember: Version control helps make project changes traceable, organized, and easier to manage.
3. How Does Git Work?
Git tracks project changes using repositories, a staging area, and commits.
Three important concepts are:
- Working directory.
- Staging area.
- Repository history.
1. Working Directory
The working directory contains the project files you can view and edit.
For example:
my-website/
├── index.html
├── style.css
└── script.js
You might edit index.html to add a heading.
At this point, the change exists in your working directory but has not yet been committed.
2. Staging Area
The staging area, also called the index, is where you prepare changes for the next commit.
You choose which changes should be included.
For example:
git add index.html
This stages the current contents of index.html.
3. Repository History
A commit records the staged project state in Git's history.
For example:
git commit -m "Add homepage heading"
The commit becomes part of the repository's recorded history.
Simple Git Workflow
Working Directory
(Edit Files)
|
| git add
v
Staging Area
(Prepare Changes)
|
| git commit
v
Git Repository
(Saved History)
Why Is the Staging Area Useful?
Imagine you modify three files:
index.htmlstyle.cssREADME.md
You want to commit only the homepage changes.
You can stage index.html and style.css while leaving README.md out of that commit.
This helps create focused, meaningful commits.
Key Point: Git does not automatically commit every file change. You choose what to stage and when to create a commit.
4. What Is a Git Repository?
A Git repository, often called a repo, is a project whose history is managed by Git.
A repository contains information about:
- Recorded file changes.
- Commits.
- Branches.
- References to project history.
- Repository configuration.
For a normal local Git repository, this information is stored inside a hidden .git directory.
Creating a Repository
Suppose you have a project folder named my-website.
Open a terminal in that folder and run:
git init
Git initializes a repository in the current directory.
You can now begin tracking changes.
What Is a Local Repository?
A local repository exists on your computer.
You can work with it even when you are offline.
What Is a Remote Repository?
A remote repository is another copy of the repository, commonly hosted on a server or collaboration platform.
Remote repositories help developers share changes and coordinate work.
Popular Git hosting platforms include:
- GitHub.
- GitLab.
- Bitbucket.
Local and Remote Repositories
Developer's Computer
Local Repository
|
Push / Fetch
|
v
Remote Repository
(Git Hosting Server)
|
Fetch / Pull
|
v
Another Developer
Local Repository
A remote repository is useful for collaboration and maintaining another copy of project history, but it is not a replacement for a complete backup strategy.
5. What Is a Commit in Git?
A commit is a recorded checkpoint in a Git repository's history.
A commit identifies a snapshot of the tracked project state and includes metadata such as the author, timestamp, and commit message.
Example
Imagine you have created the homepage of a website.
You run:
git add index.html
git commit -m "Create website homepage"
Git records the staged change.
What Is a Commit Message?
A commit message briefly describes the purpose of the change.
Good examples include:
Add contact form
Fix navigation menu
Update installation instructions
Improve mobile layout
Less helpful messages include:
changes
update
fixed stuff
final
Why Are Commits Important?
Commits help developers:
- Understand what changed.
- Review earlier work.
- Investigate bugs.
- Coordinate changes.
- Revert problematic updates.
- Document the development process.
What Is a Commit Hash?
Git identifies commits using unique object identifiers, commonly displayed as hexadecimal hashes.
A shortened example might look like:
a3f8c21
You can use a commit identifier to refer to a particular recorded version.
Beginner Tip: Make small, meaningful commits rather than combining many unrelated changes into one large commit.
6. What Is a Branch in Git?
A branch is a movable reference to a line of development in a Git repository.
Branches allow developers to work on changes without immediately modifying another branch's development history.
Example: Adding a Login Feature
Imagine a website is working correctly.
You want to add a login page, but the feature is not ready for users.
You can create a new branch:
git switch -c feature-login
Now you can develop the login feature on that branch.
The main development branch remains separate until you decide how to integrate the work.
Simple Branch Diagram
A --- B --- C
\
D --- E
In this simplified diagram:
- A, B, C: Commits on the main development line.
- D, E: Commits created for a separate feature.
- Branching: Allows development histories to diverge.
Common Branch Names
Examples include:
main
feature-login
fix-navbar
update-documentation
The default branch name depends on repository configuration. Many modern repositories use main.
Why Are Branches Useful?
- Feature Development: Build new functionality separately.
- Bug Fixes: Work on corrections without mixing unrelated changes.
- Experimentation: Test ideas without changing the main development branch.
- Collaboration: Allow multiple developers to work on different tasks.
Important: A branch is not a separate physical copy of the entire project. Git manages branches efficiently using references to commits.
7. What Is Merging in Git?
Merging combines development histories from different branches.
Imagine you finish building a login feature on feature-login.
You want to integrate that work into main.
You can switch to the target branch:
git switch main
Then merge the feature branch:
git merge feature-login
Git integrates the relevant changes into the current branch.
What Happens During a Merge?
Depending on the histories involved, Git may:
- Move the branch reference forward using a fast-forward merge.
- Create a new merge commit.
- Ask you to resolve conflicts before completing the merge.
What Is a Merge Conflict?
A merge conflict occurs when Git cannot automatically combine certain changes.
Simple Example
Two developers edit the same line of a file.
Developer A changes:
Welcome to our website
to:
Welcome to our learning platform
Developer B changes the same original line to:
Welcome to our technology portal
Git may require a person to decide which text should remain.
How Are Merge Conflicts Resolved?
A typical process is:
- Identify the conflicting files.
- Open the files and review the conflict markers.
- Decide how to combine the changes.
- Edit the files to the desired final content.
- Stage the resolved files.
- Complete the merge.
Remember: Merge conflicts are a normal part of collaborative development. They do not necessarily mean that someone made a mistake.
8. Git vs GitHub: What Is the Difference?
Git and GitHub are related, but they are not the same thing.
Git
Git is a version control system.
It helps you:
- Track project changes.
- Create commits.
- Manage branches.
- Merge development work.
- Work locally.
GitHub
GitHub is an online platform that hosts Git repositories and provides collaboration tools.
It offers features such as:
- Remote repository hosting.
- Pull requests.
- Code reviews.
- Issue tracking.
- Project collaboration.
- GitHub Actions for automation.
Git vs GitHub Comparison
| Git | GitHub |
|---|---|
| Version control software | Git repository hosting and collaboration platform |
| Can work locally | Primarily provides online services |
| Manages commits and branches | Hosts repositories and supports collaboration |
| Does not require a GitHub account | Requires an account for many platform actions |
| Open-source software | Commercial platform with free and paid offerings |
Easy Way to Remember
Git manages project history. GitHub helps people host and collaborate on Git projects.
You can use Git without GitHub.
You can also host Git repositories using other platforms or your own infrastructure.
9. Essential Git Commands for Beginners
You do not need to memorize every Git command.
Start with the commands used in everyday development.
| Command | Purpose |
|---|---|
git --version |
Check the installed Git version |
git init |
Initialize a repository |
git clone |
Copy an existing repository |
git status |
View working directory and staging status |
git add |
Stage changes |
git commit |
Record staged changes |
git log |
View commit history |
git diff |
Inspect differences |
git branch |
List or manage branches |
git switch |
Change branches |
git merge |
Combine development histories |
git remote -v |
View configured remotes |
git fetch |
Download remote history and references |
git pull |
Fetch and integrate remote changes |
git push |
Send local commits to a remote repository |
Example: Checking Git Status
git status
This shows information such as:
- Current branch.
- Modified files.
- Staged changes.
- Untracked files.
Example: Viewing Commit History
git log --oneline
Example output:
a3f8c21 Add contact form
b7d2e90 Create navigation
c1a5f44 Create homepage
These are illustrative commit identifiers.
Example: Viewing Unstaged Changes
git diff
This displays differences between the working directory and the staging area for tracked files.
To inspect staged changes, use:
git diff --staged
Beginner Tip: The most important commands to practice first are git status, git add, git commit, git log, and git diff.
10. Practical Example: Your First Git Project
Let's create a small project and record its changes.
You will need Git installed and access to a terminal.
Step 1: Check Git Installation
Run:
git --version
If Git is installed, the command displays its version.
Otherwise, install Git using the instructions for your operating system from the official Git website.
Step 2: Configure Your Identity
Set the name and email address Git will use for your commits.
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
Replace these example values with the identity you want recorded in your commits.
The email address does not need to be your public personal email; supported hosting platforms may offer privacy-preserving alternatives.
Step 3: Create a Project Folder
mkdir git-practice
cd git-practice
Step 4: Initialize Git
git init
Step 5: Create a File
Create a file named README.md using your preferred text editor.
Add:
# My First Git Project
This project helps me learn Git and version control.
Save the file.
Step 6: Check Repository Status
git status
Git should show README.md as an untracked file.
Step 7: Stage the File
git add README.md
Step 8: Create Your First Commit
git commit -m "Add initial README"
Step 9: Make Another Change
Open README.md and add:
## What I Am Learning
- Git repositories
- Commits
- Branches
Save the file.
Step 10: Review the Change
git diff
Step 11: Commit the Update
git add README.md
git commit -m "Document Git learning goals"
Step 12: View Your History
git log --oneline
You should now see two commits.
Congratulations! You have created a Git repository, tracked file changes, and recorded project history.
11. How Do Developers Collaborate Using Git?
Git becomes especially valuable when multiple people work on the same project.
Example: Building a Team Website
Imagine three developers are working on a company website.
- Developer A: Builds the homepage.
- Developer B: Creates the contact form.
- Developer C: Improves the navigation menu.
They can work on separate branches and share their changes through a remote repository.
Typical Collaboration Workflow
- Clone: Each developer obtains a copy of the repository.
- Branch: Each developer creates a branch for their task.
- Code: They make and test changes.
- Commit: They record their work locally.
- Push: They upload their branch to the remote repository.
- Review: Team members review proposed changes.
- Merge: Approved changes are integrated into the target branch.
What Is a Pull Request?
A pull request is a collaboration feature offered by platforms such as GitHub.
It allows a contributor to propose changes and request review before those changes are merged.
Pull requests can include:
- A description of the changes.
- Code differences.
- Reviewer comments.
- Automated test results.
- Approval information.
Key Point: Git provides version control capabilities, while hosting platforms add collaboration workflows around Git repositories.
12. Why Is Git Important in DevOps?
Git is widely used in DevOps because software delivery and infrastructure automation depend on managing changes reliably.
1. Source Code Management
Developers use Git to maintain application code and review modifications.
2. CI/CD Integration
Automation platforms can run workflows when changes are pushed to a repository or proposed through a pull request.
Example: A GitHub Actions workflow runs tests whenever a developer opens a pull request.
3. Infrastructure as Code
Infrastructure configuration files can be stored in Git.
Examples include configurations for:
- Terraform.
- OpenTofu.
- Kubernetes.
- Ansible.
This allows teams to review infrastructure changes before applying them.
4. Configuration Tracking
Teams can use Git to manage suitable application and infrastructure configuration files.
Important: Passwords, private keys, access tokens, and other secrets should not be committed to repositories.
5. Auditability
Git history can help teams understand:
- What changed.
- Who authored a commit.
- When a change was recorded.
- Which changes were merged.
Git history is useful evidence of project activity, but it is not by itself a complete, tamper-proof audit system.
Remember: Git supports DevOps by making changes visible, reviewable, and easier to automate.
13. Common Git Mistakes Beginners Should Avoid
1. Committing Secrets
Never intentionally store sensitive credentials in Git history.
Examples include:
- Passwords.
- API tokens.
- Private keys.
- Production credentials.
Use appropriate secret-management tools and environment-specific configuration.
2. Creating Unclear Commit Messages
Avoid messages such as:
update
changes
fix
Prefer messages that describe the purpose:
Fix login validation
Add contact form
Update deployment instructions
3. Ignoring Git Status
Before committing, run:
git status
Review what is staged and what remains untracked or modified.
4. Adding Unnecessary Files
Some generated files should not be committed.
Examples may include:
- Temporary files.
- Local editor settings.
- Build output.
- Dependency directories.
- Environment files containing secrets.
A .gitignore file helps Git ignore specified untracked files.
Important: Adding a file to .gitignore does not automatically remove it from Git history if it was already committed.
5. Using Destructive Commands Without Understanding Them
Commands such as git reset --hard can discard uncommitted work.
Beginners should understand the consequences before running commands that rewrite history or remove changes.
6. Treating Git as a Complete Backup Solution
Git tracks committed project history, but it does not automatically protect:
- Uncommitted changes.
- Every ignored file.
- External databases.
- Files outside the repository.
- All remote service failures.
Use a separate backup strategy for important data.
14. How Can Beginners Start Learning Git?
A practical learning path is more effective than memorizing commands.
Step 1: Understand Version Control
Learn why project history, commits, and branches matter.
Step 2: Install Git
Install Git on your computer and practice basic terminal commands.
Step 3: Create a Local Repository
Use:
git init
Practice adding files and creating commits.
Step 4: Explore History
Learn:
git status
git log
git diff
Understand how Git represents changes.
Step 5: Practice Branching
Create a branch:
git switch -c practice-feature
Make a small change and commit it.
Step 6: Practice Merging
Switch back to your main development branch and merge your practice branch.
Review the resulting history.
Step 7: Learn Remote Repositories
Explore:
- GitHub or another Git hosting platform.
- Cloning repositories.
- Pushing branches.
- Fetching changes.
- Pull requests.
Step 8: Build a Small Project
Create a simple website or documentation project.
Use Git to track every meaningful improvement.
Beginner Tip: Practicing Git on a small personal project will help you understand its workflow more effectively than memorizing a long list of commands.
15. Frequently Asked Questions (FAQs)
Q1. What is Git in simple words?
Git is a version control system that tracks changes in project files and helps developers manage different versions of their work.
Q2. Is Git the same as GitHub?
No. Git is version control software, while GitHub is a platform for hosting Git repositories and collaborating on projects.
Q3. Is Git free?
Yes. Git is free and open-source software.
Q4. Can I use Git without internet access?
Yes. You can create repositories, commit changes, inspect history, and manage branches locally without an internet connection.
Q5. Do beginners need Git?
Git is highly useful for beginners learning software development, DevOps, cloud engineering, and automation.
Q6. What is the difference between git add and git commit?
git add prepares changes in the staging area.
git commit records the staged project state in repository history.
Q7. What is a Git branch?
A branch is a movable reference that allows a line of development to progress independently from another branch.
Q8. Can Git track files other than code?
Yes. Git can track documentation, configuration files, scripts, and many other file types.
However, Git is generally less convenient for reviewing changes to large binary files than to text-based files.
16. Key Takeaways
Here are the most important points from this guide:
- Git is a free, distributed version control system.
- Version control helps track changes and manage project history.
- A repository contains Git-managed project history.
- The working directory contains files being edited.
- The staging area prepares changes for the next commit.
- A commit records a checkpoint in project history.
- Branches support independent development work.
- Merging combines development histories.
- GitHub provides hosting and collaboration features for Git repositories.
- Git is important in DevOps for source code management, automation, and Infrastructure as Code.
- Beginners should practice with small projects and meaningful commits.
17. What Should You Learn Next?
Now that you understand Git, continue with these related topics:
-
Git Commands for Beginners: 20 Essential Commands
- Practice the commands used in everyday development.
-
Git vs GitHub: What's the Difference?
- Explore how local version control and online collaboration work together.
-
What Is Git Branching and Merging?
- Learn how developers manage independent changes.
-
What Is CI/CD? Continuous Integration and Delivery Explained
- Understand how Git repositories connect to automated testing and deployment.
-
What Is GitHub Actions? A Beginner's Guide
- Learn how repository events can trigger automation workflows.
Continue Learning with Vyomanant Academy
Git is a foundational skill for software development, DevOps, cloud engineering, and infrastructure automation.
Vyomanant Academy helps beginners and working professionals build practical technology skills through structured learning.
Explore topics such as:
- Git and Version Control.
- Linux Fundamentals.
- DevOps and CI/CD.
- Cloud Computing.
- Docker and Kubernetes.
- Infrastructure Automation.
Start with a simple project, practice tracking changes, and gradually build confidence with collaborative development workflows.
Learn. Build. Grow.
CONTINUE EXPLORING
Recommended next
What Is Artificial Intelligence? A Simple Beginner's Guide
Learn what Artificial Intelligence (AI) means, how it works, and where we use it in everyday life, with simple examples that anyone can understand.
View resourceWhat Is Machine Learning? A Simple Beginner's Guide
Discover what Machine Learning is, how computers learn from data, and how predictions work. Explore key ML concepts, learning types, and real-world examples in this beginner-friendly guide.
View resourceWhat Is Information Technology? A Beginner's Guide
Discover what Information Technology (IT) is, how it works, its main components, everyday applications, and how beginners can start learning IT.
View resource