What is Git: Features, Command and Workflow in Git

Git is a DevOps tool used for source code management. It is a free and open-source version control system used to handle small to very large projects efficiently. Git is used to tracking changes in the source code, enabling multiple developers to work together on non-linear development. Linus Torvalds created Git in 2005 for the development of the Linux kernel. 

The following are the topics covered in this Git blog:

  • What is DevOps?
  • Tools in DevOps
  • Version Control System
  • Centralized Vs Distributed Version Control System
  • What is Git?
  • Features of Git
  • Workflow of Git
  • Branch in Git
  • Commands in Git
  • Demo on Git
Learn the basics of Git VCS and understand how to setup Git in your system with the Git Training Course. Check out the course now.

Before diving deep, let’s explain a scenario before Git:

  • Developers used to submit their codes to the central server without having copies of their own
  • Any changes made to the source code were unknown to the other developers
  • There was no communication between any of the developers

business

Now let’s look at the scenario after Git:

  • Every developer has an entire copy of the code on their local systems
  • Any changes made to the source code can be tracked by others
  • There is regular communication between the developers

business-org

What is DevOps?

DevOps is a culture that allows the development and operations teams to work together. With this type of working environment, developers continuously develop and test codes, and there is continuous integration taking place throughout the lifecycle. The operations team continuously deploys the code to the production environment. DevOps allows for better collaboration, increased trust, and faster software releases. 

dev-team

Now that we know what DevOps is, let's move on to the tools used in DevOps.

Learn the basics of Devops

Watch the beginner level video lessons for FREEGet Access Now
Learn the basics of Devops

Tools in DevOps

dev_tools

Subversion (SVN), TFS, and Git are source code management or software configuration management tools (SCM) used for both the planning and coding of the software.  

subversion

Subversion (SVN):

  • SVN is a centralized version control system
  • It is distributed under the open-source license
  • It allows you to recover older versions of your data or examine how your data changes

TFS:

  • TFS is an application lifecycle management solution that tracks issues and manages documents 
  • It has an open-source license
  • It enables you to recover older versions of your data or examine how your data changes

Git:

  • Git is a distributed version control tool
  • It is distributed under the GNU license
  • Git is used for maintaining historical and current versions of source code, web pages, etc

Version Control System (VCS)

The diagram below shows there are three files in the local system. A snapshot of these files are stored in the remote repository as Version 1. 

vcs

The following diagram includes a few changes:

snapshot

There have been some changes to file 2 and is updated to file 2.1. This change is stored as Version 2 in the repository. VCS enables you to track the history of a file collection. Each version captures a snapshot of the files at a certain point in time, and the VCS allows you to switch between these versions.

Centralized Version Control System

cvcs

  • Uses a central server to store all the files
  • Every operation is performed directly on the repository
  • All the versions of the file are stored on the Central VCS server
  • In case the central server crashes, the entire data of the project will be lost. Hence, distributed VCS was introduced.

Distributed Version Control System

  • Every programmer has a copy of all the versions of the code on their local systems
  • Distributed VCS moves from the client-server approach of central VCS to a peer-to-peer approach
  • They can update their local repositories with new data from the central server and changes are reflected in the principal repository
  • Git is one such distributed VCS tool

system-file

DevOps Engineer Master's Program

Bridge between software developers and operationsExplore Course
DevOps Engineer Master's Program

What is Git?

Git is a version control system used for tracking changes in computer files. It is generally used for source code management in software development.

  • Git is used to tracking changes in the source code
  • The distributed version control tool is used for source code management
  • It allows multiple developers to work together
  • It supports non-linear development through its thousands of parallel branches

Features of Git

  • Tracks history
  • Free and open source
  • Supports non-linear development
  • Creates backups
  • Scalable
  • Supports collaboration
  • Branching is easier
  • Distributed development

dev-git

Git Workflow

git-workflow

The Git workflow is divided into three states:

  • Working directory - Modify files in your working directory
  • Staging area (Index) - Stage the files and add snapshots of them to your staging area
  • Git directory (Repository) - Perform a commit that stores the snapshots permanently to your Git directory. Checkout any existing version, make changes, stage them and commit.

working-directory

Branch in Git

Branch in Git is used to keep your changes until they are ready. You can do your work on a branch while the main branch (master) remains stable. After you are done with your work, you can merge it with the main office.

small-feature

The above diagram shows there is a master branch. There are two separate branches called “small feature” and “large feature.” Once you are finished working with the two separate branches, you can merge them and create a master branch. 

Commands in Git

  • Create Repositories
    git init
  • Make Changes
    add
    commit
    status
  • Parallel Development
    branch
    merge
    rebase
  • Sync Repositories
    push
    pull
    add origin

DevOps Career Guide

A Guide to Becoming A DevOps EngineerDownload Now
DevOps Career Guide

Command

  • Check the version of Git.

command1

  • Set up global config variables - If you are working with other developers, you need to know who is checking the code in and out, and to make the changes.

SSPL-lp.

sspl-lp-dns.

  • If in case you need help, use the following commands:

needhelp

This will lead you to the Git help page on the browser, which will display the following:

git-help

This will lead you to the Git help page on the browser, which will display the following:

gitadd

  • Create a “test” repository in the local system.

test

  • Move to the test repository.

movetest

  • Create a new git instance for a project.

new git

  • Create a text file called info.txt in the test folder; write something and save it.

textfile

  • Check the status of the repository.

  • Add the file you created to make a commit.

add-file

  • Commit those changes to the repository’s history with a short message.

repo-hist

  • Make any necessary changes to the file and save.

file-and-save

  • Now that you’ve made changes to the file, you can compare the differences since your last commit. 

last-commit.

  • Add GitHub username to Git Configuration.

username

  • Create a remote repository.

new-repo

  • Connect the local repository to your remote repository.

local-repo

  • Push the file to the remote repository.

/push-the-file

  • Refresh your repository page on GitHub. You will get your local file on your remote GitHub repository.

refersh

  • Create three more text files in the local repository - “info1.txt”, “info2.txt”, “info3.txt”.

more-text

info3

  • Create a branch “first_branch” and merge it to the main (master) branch.

first-branch.

The above command creates a branch.

above-command.

The above command switches to the new branch from the master branch.

The above command creates and adds “info3.txt” to the first_branch.

info3text

  • Create a branch “first_branch” and merge it with the main (master) branch.

main-branch

The above command makes a commit to the first_branch.

branch

The above command shows that the new branch has access to all the files.

git-br

The above command shows that the master branch does not have an “info3.txt” file.

The above command is used to merge “first_branch” with the master branch. Now, the master branch has “info3.txt” file.

branch-last

Conclusion

I hope this blog helped you understand Git. You have learned all about before Git and after Git, what DevOps is and tools used in DevOps. You learned various essential topics, like version control systems, centralized version control systems, distributed version control systems, what exactly Git is, benefits of Git, Git workflow, branch in Git, commands in Git, and finally, you saw a demo on Git.

Git is just one tool used in DevOps. To get further training in Git, you can take up the Git Training Course or an elective course on it through Simplilearn’s DevOps Engineer Master’s Program. This comprehensive program provides you with all of the skills you’ll need and access to the most widely used DevOps tools through a combination of live, instructor-led classes, online self-paced learning, and hands-on projects. If you’re beginning or want to take your career to the next level, Simplilearn has something for all aspiring DevOps professionals. To learn more about what we’re up to, check out additional resources here.

About the Author

Sayeda Haifa PerveezSayeda Haifa Perveez

Haifa Perveez is passionate about learning new technologies and working on them. She is an engineer who loves to travel, read and write. She's always curious about things and very determined to track the latest technologies and the trends that they are creating for the future.

View More
  • Disclaimer
  • PMP, PMI, PMBOK, CAPM, PgMP, PfMP, ACP, PBA, RMP, SP, and OPM3 are registered marks of the Project Management Institute, Inc.