Git is a version control and source code management system developed for the Linux kernel. Its speed, team-based flexibility, and related open source tools have led to Git's ubiquity in recent years. It supports the use of source code branching, revision histories, and bug tracking.
This book will use Git to pull in the base templates of projects used throughout this book. The steps that are required will be illustrated in subsequent chapters.
The following is a look into the official website for Git:
Let's suppose that you have a large-scale project developed by several different programmers. Over time, you will need a feasible way to collaborate on the project without overriding each other's changes. You'll also need to be sure to keep a revision history in order to have the ability to optionally revert the changes when necessary. This way, you'll also be able to track where a bug in your code is, depending on when it was first found, by using the revision history. These are all use cases for which Git comes in handy.
There are various ways to install and run Git. The following steps will illustrate how to exactly do this on various operating systems.
Perform the following steps to install Git on Windows:
Visit http://git-scm.com/downloads and click on the Windows link.
Follow the installation steps, and Git will be installed as a command-line utility alongside an optional GUI interface.
Perform the following steps to install Git on Mac OS X:
Visit http://git-scm.com/downloads and click on the Mac OS X link.
Go through the graphical installer process and you will end up with Git installed as a command-line utility.
Perform the following steps to install Git on Linux:
Visit http://git-scm.com/downloads and click on the Linux link.
Follow the instructions on the page for your respective Linux distribution. After issuing the necessary commands in a terminal, you will end up with Git installed as a command-line utility.
In order to initialize a directory such that it may be used alongside Git, one must issue the following command:
git init
Prior to making a revision, one must add the files they have changed to a commit. To do this, you would issue the following command:
git add <file>
For example, issue the following command:
git add main.js
Once all the changed files have been added to the current revision, you are able to issue a commit, as shown in the following command:
git commit -m <commit message>
For instance, issue the following command:
git commit -m "Initial import of main.js file"
The current state of a Git-initialized directory is important. Knowing what files have been added to the current commit at any given time can help to prevent a premature commit. To query the current state, one would have to issue the following command:
git status
It also helps to reveal the current branch being used for development, a concept that will not be explored in this book.
Next, you will look into how to download a public Git repository, which can be done by inputting the following:
git clone <Git URL>
An example is shown as follows:
git clone https://github.com/packt-mg/Chapter-2.git
This command will be used throughout the book in order to download the necessary base templates for development.