What is version control?
Version control, also known as source control, is the practice of tracking and managing changes to software code. Version control tools help teams to manage changes to source code over time, work faster and smarter. These tools are especially useful for DevOps teams since they help them to reduce development time and increase successful deployments.
Source code is a precious asset for software projects, therefore its value must be protected. It represents the knowledge and understanding about the domain that developers collected. Version control protects source code from both catastrophe and casual human error and unintended consequences. Version control software keeps track of every modification to the code. If a mistake is made, earlier versions of the code can be compared to help fix the mistake while minimizing disruption of other team members.
Developers are continually writing new and changing existing source code. The source code of a project is typically organized in a folder structure. One developer can work on a new feature while another one may be fixing a bug by changing code in several parts of this structure. Version control keeps track of every change made by each contributor helping prevent concurrent work from conflicting.
Benefits of version control systems
Using a version control system is a best practice for software development and DevOps teams. It helps developers to deliver faster and increase efficiency and agility even when the team scales to include more developers. The primary benefits that you should except from a version control systems are as follows:
- A complete history of every change made to individual files. Changes include the creation and deletion of files and also modifications made to their contents. This history includes the author, date, comments and the purpose of each change.
- Branching and merging. Creating a branch keeps multiple streams of work independent from each other while also providing the capability to merge that work back together. This allows developers to verify that the changes on each brach do not conflict with other changes.
- Traceability. Each change made to the code is linked to an unit of work, e.g. task or bug. This enables developers to understand the context and the purpose of a change and also help project management with progress tracking.
What is Git?
Git is the most widely used version control system in the world at the time of writing. It is an actively maintained and developed open source project. It is based on a distributed architecture, which means every developer is working on a copy of the code that contains the full history of all changes.
Note
Git is the de facto standard version control system in software development industry.
Terminology
Below you can find fundamental terms, which are often used while working with Git. For more details see GitHub Docs.
Repository
You can think of a repository as a directory that stores all the files, folders and content needed for a project. Actually it is an object database which stores the files, file versions and metadata, commits, etc...
Branch
A version of a repository that diverges from the main working project.
Clone
Cloning is the process of creating a local copy of a repository.
Checkout
The term is used for the act switching between different branches in a repository.
Commit
Commit is a snapshot of an entire repository at a specific time.
Push
It is the act of transferring commits from local repository to remote repository.
Pull request
Pull requests lets others to know about changes that have been pushed to a branch in a repository and are potentially being merged into the base branch. To know about best practices and how pull requests are used at OSB please visit Branching Strategy and Code Review pages.
Best practices
Commit often
Commits should be made frequently to capture updates to the code base. Each commit is a snapshot that the codebase can be reverted to if needed. Commits can be combined into a single commit using rebase to keep the development log clean.
Ensure that you're working on the latest version
Source code version control tools enable rapid updates from multiple developers, which means that a local copy can fall behind of the global copy. Make sure to pull the latest code before making any updates. This helps avoid conflicts at merge time.
Use descriptive comments
Each commit has a log message populated at the time of its creation. It is important to leave a descriptive and explanatory log message. These messages should explain the purpose of the changes.
Review changes before committing
Before committing a change, make sure that the changes meet the quality standards and they don't break the code.
Use branches
Branching is a powerful mechanism that allow developers to keep their work independent from each other. Branches should be used frequently and enable developers to work in parallel on different streams. When development is completed on a branch then it can be merged back into the main code base.
Agree on ways of working
It is important to establish common workflow of contribution. Ways of working define processes for managing work items, branches and merging.