Version Control is a system used to record and manage changes made to files over time. It helps developers keep track of different versions of a project and makes it easier to work safely on source code.
Version control is a system that records changes made to files. It allows you to maintain a history of your project.
For example, if you edit a website several times, version control can help you identify when a change was made and what was changed.
Software projects often contain many files and receive frequent changes. Without version control, managing these changes can become difficult.
Version control helps developers:
Developers frequently modify source code while building applications. Version control provides a structured way to save and manage these changes.
Instead of manually creating copies of a project, developers can use a version control system to maintain the project's history.
Suppose you manually create multiple copies of a project:
website-final
website-final-new
website-final-new2
website-final-new3
After several changes, it can become difficult to understand which copy contains the latest or correct version.
With Git, you can maintain a history of changes in one repository. For example:
Initial Website
↓
Add Homepage
↓
Add Login Page
↓
Fix Login Bug
↓
Add Dashboard
Each saved point can be represented by a Git commit.
A version represents a particular state of a project at a specific point in its development.
Version control allows you to move through the history of these different states.
Version history is a record of changes made to a project. It can help developers understand how the project evolved.
In Git, you can view commit history using:
git log
Version control can identify which files have been changed. Git provides commands that help you inspect these changes.
git status
This command shows the current state of the working directory and staging area.
In Git, changes are saved into the project history using commits.
git add .
git commit -m "Save project changes"
A commit creates a saved point in the repository history.
One important benefit of version control is that previous versions of files can be inspected and, depending on the operation used, restored or reverted.
Git provides commands such as:
git restore
git revert
Version control makes it easier for multiple developers to work on the same project.
Each developer can make changes and use Git's branching and merging features to manage their work.
A branch is an independent line of development. Branches allow developers to work on features or fixes separately.
git branch login-feature
The changes can later be merged into another branch.
Version control can help you compare different states of your project. Git provides the git diff command for comparing changes.
git diff
It can show differences between files and repository states depending on how the command is used.
In a centralized version control system, the main repository is usually maintained on a central server.
Developers commonly connect to that central server to access and share project changes.
In a distributed version control system, developers can have a complete repository on their local computers.
Git is a distributed version control system.
This allows many Git operations to be performed locally.
Local version control keeps version information on the local computer. It can be useful for tracking changes made by an individual developer.
Git provides a distributed approach rather than only keeping a simple local history.
In team projects, many developers may modify the same application. Version control provides tools for organizing these changes.
Git supports branches, commits, merges and remote repositories that are commonly used in team workflows.
Sometimes two developers modify the same part of a file differently. This can result in a merge conflict.
Git identifies conflicting changes so that the developer can review and resolve them.
Version control keeps a history of project changes, but it should not automatically be considered a complete backup strategy.
Remote repositories and other backup systems can provide additional protection for important projects.
Commit messages can provide useful information about changes made during project development.
git commit -m "Add student login page"
A clear commit message makes the project history easier to understand.
Git can be used for web projects containing files such as:
It helps developers track modifications to these project files.
Python developers can use Git to manage application source code, configuration files and documentation.
python app.py
Changes to the project can then be tracked through Git commits.
Git can also manage C++ projects containing source files and headers.
main.cpp
student.cpp
student.h
Developers can track changes to these files throughout development.
Git is more than a way to save copies of files. It provides commands and features for managing the development history of a project.
Important Git concepts include:
A basic workflow can be represented as:
Edit Files
↓
Check Status
↓
Stage Changes
↓
Create Commit
↓
Continue Development
Commands commonly used in this workflow include:
git status
git add .
git commit -m "Update project"
A remote repository allows developers to share Git project history with another repository hosted on a server or online platform.
GitHub is one platform that can host Git repositories.
A common workflow using Git and GitHub is:
Create Project
↓
git init
↓
git add .
↓
git commit
↓
Connect Remote
↓
git push
The exact workflow can vary depending on the project and team.
| Term | Meaning |
|---|---|
| Repository | Location containing project and version information |
| Commit | Saved point in repository history |
| Branch | Separate line of development |
| Merge | Combining changes from branches |
| Remote | Another repository location |
| Staging Area | Area containing selected changes for the next commit |
Git provides a practical system for managing project versions. It records commits, supports branches and allows developers to work with local and remote repositories.
A simple Git workflow is:
git init
git status
git add .
git commit -m "Initial commit"
git log
In the next lessons, we will learn Git and its commands in more detail.
Question: What is the main purpose of version control?