In this guide, we'll explain what Git is, benefits of using Git, and how it works. We'll also talk about GitHub, a popular website where you can share your Git projects with others. And if you use a Linux computer, we'll show you how to install Git in Linux.
Table of Contents
What is Git?
Git is a a popular distributed source control system or version control system used to track changes in the files or in source code of a project.
Git is an open source tool developed by Linus Torvalds in 2005 for the development of Linux Kernel source code. It is completely free to use and released under GNU General Public License Version 2.
Using Git, we can easily track changes in any set of files like who has changed the code, what has been changed and when has been changed etc. The changes can be shared with a remote repository.
Git is usually used for coordinating work among programmers collaboratively developing source code during software development. It doesn’t require any central system and most of the operations are local.
The developers can see the changes of each others, add new features, resolve issues together and also see the history of entire project as they build the application.
All the project's files as well as the history of changes made to those files are stored in a folder named Repository. Usually, a Git repository is consists of files, history, config managed by git.
Every project under the distributed version control system Git, goes through four stages. The four stages of Git are:
- Working Directory: This is where you create, edit, and organize your project files.
- Staging Area: Pre-commit holding area. Also known as the "index," this is an intermediate area where you prepare changes for commit.
- Local Repository: This is where Git stores the history of your project as a series of commits.
- Remote Repository: This is typically hosted on a server (like GitHub, GitLab, Bitbucket or TFS etc.) and allows for collaboration with other developers.
The following graphical illustration explains how Git works:
The above diagram illustrates the basic workflow of Git version control system. The arrows in the diagram represent the main Git operations:
git add
: Moves changes from the Working Directory to the Staging Area.git commit
: Takes the changes in the Staging Area and creates a new commit in the Local Repository.git push
: Uploads commits from the Local Repository to the Remote Repository.git pull
: Downloads changes from the Remote Repository to the Local Repository and Working Directory.git checkout
: Allows you to navigate between branches and manage your working directory.git merge
: Allows you to integrate changes from different branches, which is fundamental to collaborative development and feature integration.
We will discuss each stage in detail when we learn about Git basics in the upcoming articles.
Important Git Terminology
The following is a comprehensive list of important Git terminology for you. This list covers the most essential terms you'll encounter when working with Git and other version control systems.
- Repository (Repo): A directory where Git has been initialized to start version controlling your files.
- Clone: A copy of a repository that lives on your computer instead of on a website's server.
- Commit: A snapshot of your repository at a specific point in time.
- Hash: A unique identifier for each commit (usually represented as a 40-character hexadecimal string).
- Branch: An independent line of development that points to a series of commits.
- Master/Main: The default branch in Git (traditionally called "master", but "main" is becoming more common).
- Merge: The process of integrating changes from one branch into another.
- Pull Request (PR): A method of submitting contributions to a project, typically used in platforms like GitHub.
- Push: Sending your committed changes to a remote repository.
- Pull: Fetching changes from a remote repository and merging them into your local branch.
- Remote: A version of your repository that's hosted on the Internet or another network.
- Origin: The default name Git gives to your main remote repository.
- Fork: A personal copy of another user's repository that lives on your account.
- Head: A reference to the most recent commit in the currently checked-out branch.
- Staging Area (Index): A file in your Git directory that stores information about what will go into your next commit.
- Stash: A place to temporarily store modified, tracked files in order to change branches.
- Tag: A reference to a specific commit, often used to mark release points.
- Rebase: The process of moving or combining a sequence of commits to a new base commit.
- Cherry-pick: Applying the changes introduced by some existing commits to another branch.
- Fetch: Downloading objects and refs from another repository.
- Diff: Showing the differences between commits, the working tree, etc.
- Submodule: A repository embedded inside another repository.
- Gitignore: A file specifying intentionally untracked files that Git should ignore.
- Hook: Scripts that run automatically every time a particular event occurs in a Git repository.
Understanding these terms will give you a solid foundation for working with Git and discussing version control concepts with other developers.
What is GitHub?
There are many hosting platforms allows you to host your Git repositories. GitHub is one of them.
GitHub is the most popular hosting platform for software development and version control using Git. With the help of GitHub, one or more developers can work on a same project and also collaborate with other developers for different projects from anywhere in the World.
There are tens of thousands of projects are hosted in GitHub. It offers both free and paid plan. GitHub is owned by Microsoft corporation.
The other notable similar hosting platforms are GitLab, BitBucket, and AWS CodeCommit. Of course there are many hosting platforms exists. But these are well known platforms for remote hosting Git repositories.
Install Git On Linux
Git is available in the default repositories of most Linux distributions.
Install Git in Alpine Linux:
$ sudo apk add git
Arch Linux:
$ sudo pacman -S git
Debian, Ubuntu, Linux mint, Pop_OS!:
$ sudo apt install git
Fedora, RHEL, CentOS, AlmaLinux and Rocky Linux:
$ sudo dnf install git
openSUSE:
$ sudo zypper install git
Once installed, you can check the version of Git using command:
$ git --version git version 2.31.1
As you can see in the above output, I have installed Git version 2.31.1.
In our upcoming tutorials, we will look into Git Fundamentals in more details.
Resource: