Chapter 1 Introduction - Docx-1
Chapter 1 Introduction - Docx-1
Chapter 1 : Introduction
What is version control system ?
Version control, also known as source control, is the practice of tracking and
managing changes to software code. Version control systems are software tools that
help software teams manage changes to source code over time.
Or
A version control system (VCS) is a tool used to manage changes to source code or
other documents over time. It helps developers track and manage modifications,
collaborate with others, and maintain a history of changes. Here’s a breakdown of
how it works and its benefits:
Key Functions:
1. Track Changes: Records changes to files, allowing users to see what has
been altered, who made the changes, and when they were made.
2. Version History: Maintains a history of all changes, so you can revert to
previous versions of files if needed.
3. Branching and Merging: Supports branching to create separate lines of
development, and merging to integrate changes from different branches.
4. Collaboration: Facilitates collaboration by allowing multiple people to
work on the same project simultaneously without overwriting each other’s
changes.
5. Conflict Resolution: Helps manage and resolve conflicts that arise when
multiple people make changes to the same file.
Benefits of the version control system:
● Enhances the project development speed by providing efficient collaboration,
● Leverages the productivity, expedites product delivery, and skills of the
employees through better communication and assistance,
● Reduce possibilities of errors and conflicts meanwhile project development
through traceability to every small change,
● Employees or contributors of the project can contribute from anywhere
irrespective of the different geographical locations through this VCS,
● For each different contributor to the project, a different working copy is
maintained and not merged to the main file unless the working copy is
validated. The most popular example is Git, Helix core, Microsoft TFS,
● Helps in recovery in case of any disaster or contingent situation,
● Informs us about Who, What, When, Why changes have been made.
or
Benefits of version Control systems :
The benefits of using a version control system (VCS) are extensive and
significantly impact the efficiency and effectiveness of managing software projects
or any collaborative document-based work. Here’s a detailed look at these benefits:
1. Enhanced Collaboration:
● Simultaneous Work: Multiple team members can work on the same project
simultaneously without conflicting with each other’s changes.
● Merging Changes: VCS tools manage and merge changes from different
contributors seamlessly, helping teams collaborate more efficiently.
2. Historical Record:
● Detailed History: Tracks and records all changes made to files, providing a
comprehensive history of what was changed, when, and by whom.
● Audit Trail: Useful for auditing purposes and understanding the evolution
of a project over time.
5. Conflict Management:
● Resolution Tools: Provides tools to detect and resolve conflicts that occur
when multiple people make changes to the same file, ensuring a smooth
integration of contributions.
6. Improved Documentation:
● Code Review Integration: Many VCS tools integrate with code review
systems, allowing peers to review and approve changes before they are
merged, which enhances code quality and consistency.
9. Efficient Workflow:
Overall, version control systems are fundamental tools that enhance productivity,
collaboration, and the overall quality of work in software development and other
collaborative environments. They provide a structured and systematic approach to
managing changes, tracking progress, and ensuring that projects are developed
efficiently and effectively.
In centralized source control, there is a server and a client. The server is the master
repository that contains all of the versions of the code. To work on any project,
firstly user or client needs to get the code from the master repository or server. So
the client communicates with the server and pulls all the code or current version of
the code from the server to their local machine. In other terms we can say, you
need to take an update from the master repository and then you get the local copy
of the code in your system. So once you get the latest version of the code, you start
making your own changes in the code and after that, you simply need to commit
those changes straight forward into the master repository. Committing a change
simply means merging your own code into the master repository or making a new
version of the source code. So everything is centralized in this model.
There will be just one repository and that will contain all the history or version of
the code and different branches of the code. So the basic workflow involves in the
centralized source control is getting the latest version of the code from a central
repository that will contain other people’s code as well, making your own changes
in the code, and then committing or merging those changes into the central
repository.
In distributed version control most of the mechanism or model applies the same as
centralized. The only major difference you will find here is, instead of one single
repository which is the server, here every single developer or client has their own
server and they will have a copy of the entire history or version of the code and all
of its branches in their local server or machine. Basically, every client or user can
work locally and disconnected which is more convenient than centralized source
control and that’s why it is called distributed.
You don’t need to rely on the central server, you can clone the entire history or
copy of the code to your hard drive. So when you start working on a project, you
clone the code from the master repository in your own hard drive, then you get the
code from your own repository to make changes and after doing changes, you
commit your changes to your local repository and at this point, your local
repository will have ‘change sets‘ but it is still disconnected with the master
repository (master repository will have different ‘sets of changes‘ from each and
every individual developer’s repository), so to communicate with it, you issue a
request to the master repository and push your local repository code to the master
repository. Getting the new change from a repository is called “pulling” and
merging your local repository’s ‘set of changes’ is called “pushing“.
It doesn’t follow the way of communicating or merging the code straight forward
to the master repository after making changes. Firstly you commit all the changes
in your own server or repository and then the ‘set of changes’ will merge to the
master repository.
Below is the diagram to understand the difference between these two in a better
way:
● Speed
● Simple design
● Fully distributed
● Able to handle large projects like the Linux kernel efficiently (speed
and data size)
Since its birth in 2005, Git has evolved and matured to be easy to use and yet retain
these initial qualities. It’s amazingly fast, it’s very efficient with large projects, and
it has an incredible branching system for non-linear development (see Git
Branching).
Why Git?
● It is free and open source software.
● It is reliable.
● Over 70% of developers use Git!
● Developers can work together from anywhere in the world.
● Developers can see the full history of the project.
● Developers can revert to earlier versions of a project.
What is GitHub?
● Git is not the same as GitHub.
● GitHub makes tools that use Git.
● GitHub is the largest host of source code in the world, and has been owned
by Microsoft since 2018.
● In this tutorial, we will focus on using Git with GitHub.
Git Install :
You can download Git for free from the following
website: https://www.git-scm.com/
To start using Git, we are first going to open up our Command shell.
For Windows, you can use Git bash, which comes included in Git for Windows.
For Mac and Linux you can use the built-in terminal.
The first thing we need to do, is to check if Git is properly installed:
Example :
git --version
Configure Git :
Now let Git know who you are. This is important for version control systems, as
each Git commit uses this information:
Example :
git config --global user.name "ravindra123"
Example :
mkdir myproject
cd myproject
Now that we are in the correct directory. We can start by initializing Git!
Initialize Git :
Once you have navigated to the correct folder, you can initialize Git on that folder:
Example :
git init
Alternatives to GitHub
While Git is one of the most popular version control systems, there are several
alternatives, each with its own features and use cases. Here are some notable
alternatives to Git:
1. Subversion (SVN)
5. Fossil
Each of these systems has its own strengths and is suited to different types of
projects and workflows. The choice of version control system often depends on the
specific needs of a project, team preferences, and integration requirements with
other tools.
Cloud based Solution
1. GitLab
GitLab is a web-based DevSecOps (take that, Call of Duty) platform that allows
software development teams to plan, build, and ship secure code all in one
application. GitLab offers a range of features and tools to support the entire
software development lifecycle, from project planning and source code
management to continuous integration, delivery, and deployment.
2. Bitbucket
Bitbucket is a Git-based code hosting and collaboration tool designed for teams. It
offers unbeatable integrations with Jira and Trello, designed to bring the entire
software team together to implement a project. Bitbucket provides a place where
your team can collaborate on code from concept to cloud, create quality code
through automated testing, and confidently deploy code.
● Exceptional integration with Jira and Trello: Structure chaos and keep the
entire software company up to date, from engineering to design. Access
branches, build statuses, commits, and Jira issues or Trello card statuses.
This is excellent for medium-sized businesses.
● Code collaboration from concept to cloud: Transition Jira issues based on the
status of pull requests, create a merge process checklist with assigned
approvers, and check for approved builds. Automatically build and test with
integrated continuous delivery.
● Deploy with confidence: Keep track of your deployments, preview them,
and promote them with confidence. Protect your code. You can rest easy
knowing that your code is secure in the Cloud and implement checks to
prevent problems before they occur.
Bitbucket offers several hosting options, including Cloud, Server, and Data Centre.
Each option has its own unique features and benefits. For example, Bitbucket
Cloud is hosted on Atlassian’s servers and accessed via a URL. It has an exclusive
built-in CI/CD tool, Pipelines, that enables you to build, test, and deploy directly
from Bitbucket.
Git Vs GitHub
Git and GitHub are related but serve different purposes in the realm of version
control and software development. Here’s a clear breakdown of their differences:
Git :
GitHub :
● Type: Platform/Service
● Function: GitHub is a web-based hosting service that uses Git for version
control. It provides a collaborative platform for managing Git repositories
with additional features like code review, issue tracking, and CI/CD
integration.
● Access: GitHub is accessed via a web interface and requires an internet
connection to interact with its remote repositories.
● Features:
o Remote Repositories: Hosts Git repositories online, making them
accessible to multiple users.
o Collaboration Tools: Includes features like pull requests, code
reviews, and issue tracking to facilitate team collaboration.
o Project Management: Provides tools like Kanban boards and
milestones to manage and track project progress.
o CI/CD Integration: Offers GitHub Actions for automating workflows
such as building, testing, and deploying code.
o Documentation: Supports README files and wikis for project
documentation.
o Community: Facilitates community engagement through open-source
projects, GitHub Sponsors, and GitHub Discussions.
Key Terminology
To clone a Git repository, you use the git clone command followed by the URL of
the repository you want to clone. Here’s the basic syntax:
If you want to clone a repository from GitHub, for example, you would do
something like this:
2. Repository in Git :
Definition : In Git, a repository (often abbreviated as repo) is a storage location
where your project's files and their version history are kept. There are two main
types of repositories in Git:
1. Local Repository: This is the repository on your own machine. It contains
all your project files, as well as the entire history of commits and branches
related to your project. When you clone a repository from a remote server,
you create a local copy on your machine.
2. Remote Repository: This is a repository hosted on a server or a cloud
service (like GitHub, GitLab, Bitbucket, etc.). Remote repositories are used
for collaboration and sharing code with others. They allow multiple people
to contribute to the same project and keep track of changes made by
different contributors.
● Working Directory: The directory where you modify files. It contains the
current state of your project files.
● Index (Staging Area): A file, also called the index, that acts as a staging
area where you prepare changes before committing them.
● Commit History: A record of all changes made to the project. Each commit
is a snapshot of the project at a specific point in time.
To interact with a Git repository, you use commands such as git init to create a new
repository, git clone to copy an existing one, git add to stage changes, and git
commit to save changes to the repository's history.
3.Working Tree : In Git, the working tree (or working directory) refers to
the directory on your local filesystem where you make changes to your project
files. It's the area where you work on your code, add new files, edit existing ones,
or delete files. The working tree represents the current state of your project as it
exists on your local machine.
1. Working Tree: This is the actual directory on your filesystem where you
have your project files. Any changes you make here are initially untracked
by Git until you explicitly add them to the staging area.
2. Index (Staging Area): Once you make changes in your working tree, you
use commands like git add to move those changes to the staging area. This
area is where you prepare changes before committing them.
3. Repository (Git Directory): This contains the actual version control data,
including the commit history, branches, and tags. It is typically stored in a
hidden directory named .git in the root of your project. This directory keeps
track of all the changes and versions of your project files.
The staging area is an intermediary space where you prepare and organize your
changes before committing them to the repository. It allows you to review and
select specific changes to include in your next commit, giving you control over
what gets saved in the project's history.
5.Git Stash :
The git stash command is a powerful feature in Git that helps you temporarily set
aside changes in your working directory and staging area. This can be useful when
you need to switch contexts or branches but don't want to commit your current
work just yet. Here’s a breakdown of how it works and how to use it:
● Temporarily Saves Changes: git stash saves your local modifications (both
staged and unstaged) to a stack-like structure, so you can revert to a clean
working directory.
● Restores Later: You can later reapply these changes to your working
directory with git stash apply or git stash pop.
6. Git Checkout :
The git checkout command in Git is a versatile command used for several
important tasks related to branch management and file restoration. Here's a detailed
explanation of its primary uses:
1. Switching Branches
3. Restoring Files
7. git pull
git pull is used to update your local repository with changes from a remote
repository. It retrieves (or "pulls") new commits from a remote branch and
integrates them into your current branch.
● Command:
● Command:
2. Commits
A commit is a snapshot of your project at a specific point in time. Each commit
has a unique identifier (hash) and includes a message describing the changes made.
Commits allow you to track and review the history of your project.
3. Branches
A branch is a separate line of development. The default branch is
called main or master. You can create new branches to work on features or fixes
independently. Once the work is complete, the branch can be merged back into the
main branch.
4. Merging
Merging is the process of integrating changes from one branch into another. It
allows you to combine the work done in different branches and resolve any
conflicts that arise
5. Cloning
Cloning a repository means creating a local copy of a remote repository. This copy
includes all files, branches, and commit history.
Git Bash
Git Bash is an application that provides a Git command line interface
(CLI) emulation for Microsoft Windows. It allows users to run Git commands and
interact with a repository, as well as offering Unix command line features.
Essentially, Git Bash brings the powerful functionalities of Unix-based systems to
Windows, making it easier for developers to manage and control their projects.
Why Use Git Bash?
1. Compatibility: Git Bash is designed to be fully compatible with Git, making it
a crucial tool for developers who use Git for version control.
2. Powerful Command Line Tools: It provides a range of Unix command line
tools, which are often preferred by developers for their flexibility and power.
Ease of Use: With Git Bash, you get a familiar Bash experience on Windows,
which is particularly useful for those who are accustomed to Unix/Linux
environments. In Git, the term checkout is used for the act of switching between
different versions of a target entity. The git checkout command is used to switch
between branches in a repository.