Learn Git and GitHub : Essential for DevOps Engineers

Learn Git and GitHub : Essential for DevOps Engineers

As technology advances, it is becoming important for DevOps engineers to have a good understanding of version control systems and collaboration tools. Git is a powerful version control system, while GitHub is a popular platform for hosting Git repositories and collaborating with team members.

In this blog, we will learn Git and GitHub basics and how these tools can improve your software delivery and make you a more effective DevOps engineer.

First of all, What is a version control system?

A version control system (VCS) is a software tool that helps developers manage changes to source code over time. It enables developers to track changes made to files, collaborate on code with other team members, and easily revert to earlier versions of code if necessary.

This VCS stores these file/code versions inside a repository that can be accessed by multiple developers to work on it. According to the availability of this repository to developers, VCS is of two types:

  1. Centralized Version control system

  2. Distributed version control system

1. Centralized Version control system [CVCS]

CVCS is a system where a single central repository is used to store the source code of a project, and developers check out files from this repository to make changes. This means that developers need to be connected to the central server to access the code. Examples of CVCS include Subversion and CVS.

2. Distributed Version control system [DVCS]

DVCS, Allows for multiple copies of the code to exist, each with its full history of changes made to it. Developers copy the entire code to their local machine and work offline, and changes can be merged later to the original repository copy. Examples of DVCS include Git and Mercurial.

What is GitHub?

GitHub is an online platform that allows developers to store and manage their code, collaborate with others, and track changes to their projects. It is like a virtual workspace for developers where they can work on software development projects together with other developers, share their code, and keep track of changes made to their projects.

Let's Start with creating a git repository--->

  1. On your local machine (Ubuntu OS my side)

    • Check whether the git tool is installed on your system, If not then install it first-----> Git - Installing Git (git-scm.com)

      $ git --version

    • Make a new directory and enter inside it. Then type the below command to make it a git repository.

      $ git init

      You are done with a local git repository named demo-repo.

  2. On your GitHub account

    • Create a GitHub account and login to it. You will find a new repository icon on the right top of the page.

    • Click on the New button and provide a name to your repository and tick README.md. Click "Create repository" and you are done.

The three-stage architecture of Git

Which includes:

  1. Working Directory: This is where you make changes to your files.

  2. Staging Area (or Index): This is where you can selectively stage changes from the working directory for the next commit.

  3. Git Repository: This is where Git stores committed changes as a permanent record of the project's history.

    3 Git – Three stage architecture - CodeTej

Git's three-stage architecture simplifies the process of managing changes in code, allowing developers to work on different branches and merge their changes efficiently.

Now practice some basic git commands to learn the git using the Command line interface--->

Here are some common Git commands with their descriptions.

  1. git init - initializes a new Git repository.

  2. git add [filename] - adds changes to the staging area.

  3. git commit -m "commit message" - creates a new commit with the changes from the staging area.

  4. git status - displays the status of the working directory and staging area.

  5. git log - displays the commit history.

  6. git restore [filename] - get the previous file version back to the file system.

  7. git branch - lists existing branches or creates a new branch.

  8. git checkout -b [branch name] - create a new branch from the current branch

  9. git checkout [branch name] - switches to a different branch or a specific commit.

  10. git merge [branch name] - combines changes from different branches into the current branch.

  11. git remote -v - check connections to the remote repository.

  12. git remote add origin [remote repo url] - create a remote repo access named origin

  13. git push origin [branch name] - sends committed changes to a remote repository.

  14. git pull origin [branch name] - fetches changes from a remote repository and merges them into the local branch.

  15. git clone [remote repo url] - creates a local copy of a remote repository.

  16. git config - sets or retrieves Git configuration options.

  17. git config --global user.name "username" - username for git accountability.

  18. git config --global user.email "user email id" email id git accountability.

  19. git diff [branch name] - displays differences between the current branch and provided branch.

Importance of GitHub for DevOps Engineers

GitHub provides a centralized platform for version control, code collaboration, and project management.

DevOps engineers use GitHub in several ways, including:

  1. Source Code Management: GitHub provides a centralized platform for version control and source code management, enabling DevOps engineers to collaborate on code changes, track versions, and manage code repositories.

  2. Continuous Integration and Deployment (CI/CD): GitHub integrates with a variety of CI/CD tools, allowing DevOps engineers to automate the build, test, and deployment process.

  3. Issue Tracking and Project Management: GitHub includes powerful tools for issue tracking and project management, enabling DevOps engineers to manage tasks and projects more efficiently and collaborate effectively with other team members.

  4. Code Quality and Security: GitHub includes built-in tools for code quality and security analysis, such as code scanning tools and code coverage tools, allowing DevOps engineers to identify and address potential issues early in the development process.

  5. Community and Open Source Development: GitHub is home to a large and vibrant community of developers and open source projects, providing opportunities for DevOps engineers to collaborate, share code and best practices, and contribute to open source projects.

Overall, GitHub is an essential tool for DevOps engineers, providing a platform for efficient and collaborative software development and enabling them to automate and streamline the software development process.

Summary:

In this article, we learned about what Git and GitHub are, the different types of Version Control Systems (VCS), Git's three-stage architecture, basic Git commands, and the importance of Git and GitHub for a DevOps engineer. Understanding Git and GitHub is crucial for DevOps engineers as it allows for easy collaboration, version control, and efficient management of code changes.

Using Git and GitHub, DevOps engineers can streamline their development process, minimize errors, and improve overall project efficiency.

Stay tuned for my next blog on "Advanced - Git and GitHub". I will keep sharing my learnings and knowledge here with you.

Let's learn together! I appreciate any comments or suggestions you may have to improve my blog contents.

Thank you,

Chaitannyaa Gaikwad

Did you find this article valuable?

Support Chaitannyaa Gaikwad by becoming a sponsor. Any amount is appreciated!