DevOps: Git for Beginners!

Software development and related methodologies have come a long way with the advent of agile and lean methodologies as well as DevOps. Now, automation has been introduced to enable frequent and faster releases in small chunks so that new features and software reach the target audience in a much quicker way. Collaboration through tools, such as Git, is at the heart of this new software development methodology.

To work on modern software development projects, you must be proficient at using Git. In this article, we will discuss what Git is, its terminologies, its roles and tools, and the basic Git commands.

Welcome to KodeKloud!

We are the #1 DevOps courses provider. Register today to gain access to the richest collection of DevOps courses and labs and try sample lessons of all our courses.

No credit card required!

START FREE!

What is Git?

Git is a Version Control System (VCS) created by Linus Torvalds, who is also the creator of the Linux Operating System. On a fundamental level, there are two remarkable things a VCS allows you to do:

  • Track changes you make to your files, and it
  • Enhance collaboration by simplifying working on projects with multiple people and teams.

Git is a software that runs locally on the developers’ machine. The files and history are stored on the developers’ computer. Developers can also use online hosts, such as GitHub and Bitbucket, to save a copy of their files and revision history. These online hosts provide a central place to upload changes and download changes from others, enabling seamless collaboration.

With Git, two or more developers can work on different parts of the same file and later merge the changes without waiting for each other and losing each other’s work.

Why GIT?

Software development involves a team of developers working together on the same code base. Git allows multiple developers to work on the same code base simultaneously without having to worry about conflicts. It does this by providing a centralized repository where all the changes are stored and versioned. This helps developers easily collaborate on the same project and keep track of the changes made to the code over time.

With Git, you can see what others are working on, review their code, view your previous changes, roll back to previous code, and do much more.

How to get Git?

To get started with Git, you first need to install it on your local machine.

  • You can download git for any operating system here.
  • Try GitHub Desktop (for Windows and Mac) if you like to use a graphical user interface (GUI).

Git Terminologies

Git key terminologies include:

  1. Version Control System: A version control system - such as Git - is a software tool that helps keep track of changes made to a project's source code over time. It allows developers to collaborate on a project by tracking who made changes, what changes were made, and when they were made. This helps ensure that changes made to the codebase don't conflict with each other and that previous versions of the code can be easily accessed if needed.
  2. Commit: A commit is a snapshot of the changes made to a file or multiple files. It is like a save point that you can revert to if needed. When you commit changes in Git, you create a record of the changes that have been made, along with a message that describes the changes. This allows you and your team to track who made the changes when they were made, and what was changed. Each commit in Git is identified by a unique hash, which can be used to refer to that specific commit in the future.
  3. Push – When you make changes to your local Git repository, you'll typically want to share those changes with others or back them up to a remote repository, and the "push" command is used to do this. It's an essential operation in Git that allows you to share your work with others and keep the remote repository up to date.
  4. Pull – The "pull" command is used to fetch and download content from a remote repository and immediately update the local repository to match that content. It's essentially the opposite of the "push" command, as it retrieves changes made by others and applies them to your local repository.
  5. SHA (Secure Hash Algorithm): It is a unique identifier generated by Git for every commit, file, and tree object in a repository. This hash is a 40-character string of hexadecimal characters, and it serves as a unique fingerprint for the object it identifies. The hash is used to track changes in the repository, ensuring that every file version is uniquely identifiable and retrievable. Git uses a cryptographic hash function called SHA-1 to generate the hash for each object. The hash value is also used to ensure the integrity and authenticity of the objects in the repository.
  6. Branch: A branch is a lightweight movable pointer to a commit. It is a way to work on different versions of a repository simultaneously. When a new branch is created, it is a copy of the current branch, and any changes made to the new branch don't affect the original branch until they are merged back together. Branches in Git are useful because they allow developers to experiment with new features or bug fixes without affecting the main codebase.
git branches

Role of GIT in DevOps

As a DevOps tool, Git empowers teams to work more efficiently and effectively, reducing errors and improving the overall quality of the software being developed. This plays a crucial role in enabling faster release cycles, which aligns with the principles of DevOps.

Git is crucial when working in large organizations where multiple teams collaborate on the same project, and each team needs to track changes made. That’s why anyone who wishes to have a career in DevOps should start by understanding Git.

Almost every company is now powered by software in one way or another. There are multiple projects handled by many developers in an organization, and they all need a means to track, upload, and receive changes to the code base. Effective repository management services are the key to fast and efficient software development. The most popular ones based on Git are GitHub, Bitbucket, and GitLab.

GitHub

GitHub is a git-based repository host launched initially in 2008 by PJ Hyatt, Tom Preston-Werner, and Chris Wanstrath. Now, GitHub is the largest repository hosting platform, with over 38 million projects. It is authorized to host and review code, manage projects, and build software.

Bitbucket

Bitbucket was also launched in 2008 by an Australian startup and it initially supported only for Mercurial projects. In 2010 Bitbucket was smartly bought by Atlassian, and the next year, it started supporting Git hosting, which is now its primary focus. Bitbucket has become a household name and provides free unlimited private repos, many powerful integrations like Jira and Trello, and built-in continuous delivery.

GitLab

GitLab started as a small project in 2011, aiming to provide an alternative to the available repository management solutions. The company was only incorporated in 2014. GitLab now provides a complete DevOps setup for organizations, from CI/CD, to agile development, to security, etc.

Here is a basic Git cheat sheet you would love to have.

Basic Git command

Below are some of the basic Git commands:

  • Install git
yum install git
  • To see the version of git installed
git version
  • To initialize a git repository
git init
  • To check the status of the git repository
git status
  • To track all the files except notes.txt file
git add LICENSE README.md main.py
  • To stage changes
git add main.py
  • To commit changes
git commit -m "initial commit"
  • To copy a repository
git clone username@host:/path/to/repository
  • To set user-specific configuration values like email, username, file format, and so on
git config --global user.email [email protected]
  • To view all remote repositories
git remote -v
  • To create or delete branches
git branch

Git is the most basic requirement in the software development and DevOps field.

Difference between Git and GitHub

One of the most common questions we get asked is the differences between Git and GitHub. Git is the tool/technology that allows versioning of code, and GitHub is the centrally hosted Git server where the Git repository lives. Developers use the remote repository hosted on Github to share their work among themselves. GitHub is just one of the many tools alongside Gitlab, BitBucket, etc.

Enroll in our Git for Beginners Course.

GIT for Beginners | KodeKloud
Learn Git with simple visualisations, animations and by solving lab challenges

Myth: Git is only for Software Developers

Git is not just for developers. Git is for anyone working in IT – from Systems Administrators to Solutions Architects, Software Engineers, Team leads, and Project managers – who should equally learn and understand the workflows in Git.

With the advent of Infrastructure as Code, System administrators and operations teams use Git to store code related to infrastructure, such as Terraform Configuration files, Ansible Playbooks, Vagrant files, and supporting shell scripts.

Myth: GitHub is just a code base/repository

Git is not just a code repository. Git is where new software is developed. Today most of the popular projects are developed on Github – Kubernetes, Ansible, Terraform, Tensorflow, Helm Charts being a few of the top repositories. All of these projects have extensive documentation built on GitHub.

Want a quick introduction to Git? Watch this video.