1.2. What is Git?#
Git was created by Linus Torvalds in 2005, the same individual who developed the Linux operating system. Since its inception, Git has been maintained by Junio Hamano, who has played a crucial role in its ongoing development and stability.
To navigate the world of Git, it’s essential to familiarize yourself with its unique terminology. Here’s a concise glossary of terms that you’ll encounter frequently as you delve into Git. Don’t worry about grasping all the details immediately; these terms will become second nature as you progress through the exercises in this book.
1.2.1. Working Tree#
The working tree consists of the nested directories and files that make up the project you are currently working on. Think of it as the active workspace where all your changes and edits occur.
1.2.2. Repository (Repo)#
The repository, or repo, is the directory at the top level of your working tree where Git stores all the project’s history and metadata. A bare repository is a special type of repo that doesn’t include a working tree; it’s typically used for sharing or backups. Bare repos usually have names ending in .git
, such as project.git
.
1.2.3. Hash#
A hash is a unique number generated by a hash function, representing the contents of a file or another object as a fixed number of digits. Git uses 160-bit hashes (SHA-1) to track changes. By hashing a file’s contents and comparing it to a previous hash, Git can determine if the file has changed, regardless of its timestamp.
1.2.4. Object#
In a Git repository, there are four types of objects, each identified by a unique SHA-1 hash:
Blob Object: Contains the content of an ordinary file.
Tree Object: Represents a directory and contains names, hashes, and permissions.
Commit Object: Represents a specific version of the working tree.
Tag: A name attached to a commit, marking it for reference.
1.2.5. Commit#
To commit, in Git terminology, means to create a commit object. This action is akin to committing changes to a database; it records your changes so that others can eventually see them. A commit in Git is a fundamental concept that represents a snapshot of your repository at a specific point in time. Each commit records changes to the files in your repository and includes metadata such as the author, date, and a commit message. Each commit has a unique identifier (SHA-1 hash)
1.2.6. Branch#
A branch is a named series of linked commits. The most recent commit in a branch is known as the head. When you initialize a repository, Git creates a default branch called main
, though it is often named master
. The head of the current branch is named HEAD
. Branches enable developers to work independently (or collaboratively) on separate lines of development and later merge their changes into the main branch.
1.2.7. Remote#
A remote is a named reference to another Git repository. When you create a repo, Git sets up a default remote named origin
for push and pull operations. This can be changed as well.
1.2.8. Commands, Subcommands, and Options#
Git operations are executed through commands like git push
and git pull
. Here, git
is the command, and push
or pull
is the subcommand specifying the operation you want Git to perform. These subcommands are often accompanied by options, which are indicated with hyphens (-) or double hyphens (–), such as git reset --hard
.
These terms and others, like push
and pull
, will become clearer as you continue learning. Refer back to this glossary as needed to reinforce your understanding while you work through the module.
1.2.9. Installing git
#
git
comes default in Linux systems. In a terminal try out
git --version
If git
is not installed by default, then open a terminal and try to install git
as
If Debian/Ubuntu based distributions
sudo apt update && sudo apt install git
If Fedora based distributions
sudo dnf install git
If Arch based distributions
sudo pacman -S git
git comes installed by default in MacOs systems. In a termnial try out
git --version
If git
is not installed by default, then open a terminal and try to install git
as
Installing using
brew
installerbrew install git
.Alternatively, you can install using Xcode command line tools as
xcode-select --install
Download the executable from https://git-scm.com/download/win
Run the installer and follow the on-screen instructions.
Use the default settings unless you have specific requirements.
Once installed open
cmd.exe
and check out the versiongit --version
Great… Congratulations !!! Now you have git installed in your system.