loading...
Cover image for DevOps: Git for Beginners

DevOps: Git for Beginners

kodekloud profile image KodeKloud ・6 min read

Software development and related methodologies have come a long way with the advent of Agile, Lean, and DevOps. Now, it is all about Automation - frequent and faster releases in small chunks, so the features and software reach the target audience in a much quicker and more efficient way. DevOps has become a center stage, and every software developer wants to learn more about modern software development approaches and tools. One such tool is 'Git,' and is a must-know for every developer out there.

Git is a must for anyone who writes code or is involved in a DevOps Project. In this article, we will discuss what Git is and other concepts related to it.

What is Git?

Alt Text
Git was developed by Linus Torvalds, the creator of Linux Operating System. Git is a Version Control System (VCS), which is more commonly used than the alternatives. On a fundamental level, there are two remarkable things a VCS allows you to do:

  • Track changes you make to your files
  • It enhances 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. A central place to upload changes and download changes from others enables collaboration easily between the teams.

Git can automatically merge the changes; that way, two 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. To avoid code conflict between these developers, we need a centralized version control system like Git. Git helps developers go back to older versions of the code base to make revisions such as fix bugs or revert code changes. With branches Git helps developers work on multiple feature implementations or bug fixes in parallel and later merge those changes in when ready..

With Git, you will be able to 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?

Git usually is installed by default on many systems.

  • 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).

  • Well, if you want to download it from scratch, this link has details on installing Git on multiple operating systems.

Git key concepts

Git key terminologies include:

  • Version Control System:Git helps maintain various versions of the code base at different stages of the development lifecycle. It is also called a source code manager.

  • Commit: When a developer makes code changes, the changes are saved in the local repository. Every commit saves a copy of the changed/added files within Git.

  • Push - This sends the recent commits from developers' local repository to a remote server like GitHub, GitLab or BitBucket.

  • Pull - This downloads any changes made from the remote Git repository and merges them into the developers' local repository.

  • SHA (Secure Hash Algorithm): This is a unique ID given to each commit.

  • Branch: When you diverge from the main line of software development and continue to work/code without messing with the main/master development line.

Role of GIT in DevOps

The DevOps approach needs a version control system that will track all the changes. Git is a distributed version control system that allows developers to keep a local copy of the commits they make. GIT as a DevOps tool empowers collaboration and faster release cycles, and that is what the DevOps concept is based upon.

Version control is one of the best practices of DevOps. With version control, developers working on a project have the ability to version the software, share, collaborate, merge, and have backups.

When working in large organizations, where multiple teams work together on the same project, Git comes handy and makes it easy to track changes made by each team. It helps in tracking code, version control, and effective management of code.

Anyone willing to start or approach DevOps as a career should start from the basics, and GIT is the fundamental tool that overrides everything else.

Most popular Git solutions

Every company is now powered by software in one or the other ways. 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.
Alt Text

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

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 from 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 has built-in continuous delivery.

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 the organizations from continuous integration and delivery, agile development, security etc.

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

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 youremail@example.com

  • 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.

This video will walk you through the basics of Git.

Difference between Git and GitHub

One of the most common questions we get asked are 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 such as Gitlab, BitBucket etc.

Alt Text
Image source credits: TheServerSide

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, Project managers - should equally learn and understand the workflows in Git.

With the advent of Infrastructure as Code, System administrators and operations teams will be using Git to store code related to infrastructure such as Terraform Configuration files, Ansible Playbooks, Vagrant files, 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. The Git workflow was built with collaboration between developers in mind. Code reviews and approvals happen on Github. Github has a Project dashboard that enables project management.

Checkout our new course on Git for Beginners here

Discussion

pic
Editor guide
Collapse
theelibazz profile image
TheElibazz

Very helpful. Thanks

Collapse
zaid015 profile image
zaid015

Always nice to read this kind of blogs before sleeping. Thank You :))