02-032 - Additional Reading - Git Basics
02-032 - Additional Reading - Git Basics
02-032 - Additional Reading - Git Basics
Additional Reading
Introduction
Knowing how to use version control is a crucial skill for any developer working on a
project, especially when working in a team of developers. The source code of a project is
an extremely precious asset and must be protected. Version control software tracks all
changes to the code in a special kind of database. Therefore, if a developer makes a
mistake, they can compare earlier versions of the code to the current version to help fix
the mistake while minimising disruption to the rest of the team. Here, we will introduce
you to the basics of version control. It focuses on the Git version control system and the
collaboration platform, GitHub.
Extra resource
A version control system is one of the most important tools for any software developer!
Check out this HyperionDev blog post to see the other four tools essential for all
developers.
Version control is independent of the kind of project, technology, or framework you are
working with. For instance, it works just as well for an Android app as it does for an
HTML website. It is also indifferent to the tools you work with. You can use it with any
kind of text editor, graphics program, file manager, etc.
By using a version control system, everybody on the team is able to work on any
file at any time. The version control system then allows you to merge your
changes into a common version, so the latest version of the project is stored in a
common, central place.
● Restoring previous versions: being able to restore older versions of a file enables
you to easily fix any mistakes you might have made. Should you wish to undo any
changes, you can simply restore your project to a previous version.
● Backup: a version control system can also act as a backup. Every member of the
team has a complete version of the project on their disk. This includes the
project’s complete history. If your central server breaks down and your backup
drive fails, you can recover your project by simply using a team member’s local
repositories.
As well as being distributed, Git has been designed with performance, security, and
flexibility in mind.
Installing Git
Before you start learning how to use Git, you must install it. Even if you already have it
installed, you should ensure that you update it to the latest version. Below are the
instructions on how to install Git on Windows, Mac, and Ubuntu:
2. After starting the installer, you should see the Git Setup wizard screen. Click on
the “Next” and “Finish” prompts to complete the installation.
4. Configure your Git username and email using the following commands:
3. Open a terminal.
4. Verify that the installation was successful by typing the following command into
the terminal:
git --version
5. Configure your Git username and email using the following commands:
2. Verify that the installation was successful by typing the following into the
terminal:
git --version
3. Configure your Git username and email using the following commands:
Extra resource
If you’re using a different Linux/Unix distribution, you can use Git-SCM to download Git
using the native package manager on numerous platforms.
Repositories
A repository can be thought of as a kind of database where your version control system
stores all the files for a particular project. A repository in Git is a hidden folder called
‘.git’, which is located in the root directory of your project. Fortunately, you do not have
to modify anything in this folder. Simply knowing that it exists is good enough for now.
There are two types of repositories, namely, local repositories and remote repositories. A
local repository is located on your local computer as the ‘.git‘ folder inside the project's
root folder. You are the only person that can work with this repository. A remote
repository, however, is located on a remote server on the internet or in your local
network. Teams of developers use remote repositories to share and exchange data.
These serve as a common base where everybody can publish and receive changes.
You can get a repository on your local machine in one of two ways:
● You can initialise a new repository that is not yet under version control for a
project on your local computer.
● You can get a copy of an existing repository. For example, if you join a company
with a project that is already running, you can clone this repository to your local
machine.
Commit
A commit is a wrapper for a set of changes. Whenever someone makes a commit, they
are required to explain the changes that they made with a short commit message so
that, later on, people looking at the project can understand what changes were made.
Every set of changes creates a new, different version of your project. Therefore, every
commit marks a specific version. The commit can be used to restore your project to a
certain state as it’s a snapshot of your complete project at a certain point in time.
This leads to the main sections of a Git project: the working directory, staging area,
and Git repository. A working directory consists of files that you are currently working
on. The staging area is a file that is contained in the Git repository. It stores information
about what will go into your next commit. The staging area acts as the interface
between the repository and the working directory. All changes added to the staging
area will be the ones that actually get committed into the Git repository, which is where
Git stores the metadata and object database for your project.
3. Perform a commit operation to move the files from the staging area and store
them permanently in the Git repository.
GitHub
GitHub is an online Git repository hosting service. It is free to use for open-source
projects and offers paid plans for private projects.
GitHub offers all of the functionality of Git while also adding its own features. While Git
is a command-line tool, GitHub provides a web-based graphical interface. It provides
access control and many features that assist with collaboration, such as wikis and basic
task management tools for all projects.
Each project hosted on GitHub will have its own repository. Anyone can sign up for an
account on GitHub and create their own repositories. They can then invite other GitHub
users to collaborate on their project.
Extra resource
Check out this HyperionDev blog post about Git and GitHub. It provides a simple
guide to GitHub for beginners.
2. Once you have successfully downloaded and installed Git, enter git --version
into your terminal or command prompt to display your current version of Git.