A crash course on Git – Source Code Management with Git and GitOps

Git is the most popular source code management system available these days, and it has now become mandatory for all developers to learn Git, at least the basic stuff. In this crash course, we will learn about all basic Git operations and build from them in the subsequent chapters.

Git is a distributed version control system. This means that every Git repository is a copy of the original, and you can replicate that to a remote location if needed. In this chapter, we will create and initialize a local Git repository and then push the entire repository to a remote location.

A Git repository in a remote central location is also known as a remote repository. From this central repository, all developers sync changes in their local repository, similar to what’s shown in the following diagram:

Figure 2.1 – Git distributed repository model

First, let’s install Git locally and initialize a local repository. We will look at a remote repository later.

Installing Git

Depending on your platform and workstation, there are different ways to install Git. To install Git on

Ubuntu, run the following command:

$ sudo apt install -y git-all

For other OSs and platforms, you can follow the steps at the following link: https://git-scm.

com/book/en/v2/Getting-Started-Installing-Git.

To check if Git has been installed successfully, run the following command:

$ git –version

git version 2.30.2

Now, let’s initialize our first Git repository.

Initializing your first Git repository

To create a Git repository, you need to create a directory and run the git init command, as shown here:

$ mkdir first-git-repo && cd first-git-repo/

$ git init

Initialized empty Git repository in ~/first-git-repo/.git/

You are now ready to use your Git repository. You can also see that when you initialized the Git repository, Git created a hidden directory, .git, which it uses to keep track of all changes and commits. Whatever changes you make in your repo, Git keeps them as a delta of changes, which it depicts using + and – signs. We will look at these in detail in the subsequent sections. For now, let’s create a new file within our Git repository and stage it for changes.

About the Author

Leave a Reply

Your email address will not be published. Required fields are marked *

You may also like these