Day 12 Task: Deep Dive in Git & GitHub for DevOps Engineers

Faizan ShaikhFaizan Shaikh
4 min read

Deep Dive in Git & GitHub for DevOps Engineers

As DevOps engineers, mastering Git and GitHub is crucial because they form the backbone of version control and collaboration in software development. In this blog, I will break down the key concepts of Git, its importance, and how to use it effectively with GitHub. I'll also address some common questions in a way that blends theory and practical use cases, accompanied by simple hand-made diagrams for better understanding.

What is Git and Why is it Important?

Understanding Git:

Git is a distributed version control system (VCS) that allows developers to track changes in their code, collaborate on projects, and manage project history over time. Unlike traditional VCS systems that rely on a central server, Git enables each developer to have a full-fledged repository on their local machine.

Importance of Git:

  1. Version Tracking: Git records each change made to a file, ensuring a complete history of project development.

  2. Collaboration: Multiple developers can work on the same project, track changes, and merge code seamlessly.

  3. Branching: Git’s branching model allows developers to work on multiple features or bug fixes in isolation, without affecting the main codebase.

  4. Distributed Workflow: Since every contributor has a full copy of the repository, the system is more resilient to failures and facilitates offline work.

Simple Hand-Made Diagram:

rustCopy codeMain Project Repository
     |
    V
[ Developer 1's local repo ] <--> [ Developer 2's local repo ] <--> [ Developer 3's local repo ]

What is the Difference Between the Main Branch and the Master Branch?

Historically, Git used "master" as the default branch name. However, in recent times, the community has shifted toward using the term "main" for inclusivity. Functionally, both terms represent the default branch in a Git repository where stable, production-ready code is stored. The difference is purely naming, and users can decide to name their branches as they wish.

Key Points:

  • Master: The default branch in older Git repositories.

  • Main: The modern default branch used by many new repositories, especially on GitHub.

Can You Explain the Difference Between Git and GitHub?

Git:

  • Functionality: Git is a local version control system, designed to manage and keep track of source code changes. It is purely a tool for managing versions, branches, and commits on your local machine.

  • Installation: Git runs locally on your system and doesn’t need an internet connection to perform most operations.

GitHub:

  • Functionality: GitHub is a cloud-based platform that provides hosting for Git repositories. It offers additional features like collaboration, issue tracking, project management, and more.

  • Purpose: While Git allows you to manage code locally, GitHub enables you to share it with others, host repositories, and collaborate on projects online.

Simple Hand-Made Diagram:

How Do You Create a New Repository on GitHub?

Here are the steps to create a new repository on GitHub:

  1. Log in to your GitHub account.

  2. Click the New button or navigate to Repositories > New.

  3. Name your repository, for example, "DevOps."

  4. Choose the visibility (public or private).

  5. (Optional) Add a README, .gitignore, or license file.

  6. Click Create Repository.

Now, you have a repository where you can push your local Git repository code.

What is the Difference Between a Local and Remote Repository? How to Connect Local to Remote?

Local Repository:

A local repository is the one stored on your machine, containing the project history and all changes made locally.

Remote Repository:

A remote repository is a version of your repository hosted on a cloud platform like GitHub. It enables you to collaborate with others and back up your code.

Connecting Local to Remote:

  1. Clone an existing repository:

     git clone <remote-repo-url>
    
  2. Connect a local repo to a remote: If you already have a local repository, connect it to a remote repository using:

     git remote add origin <remote-repo-url>
    

    This command tells Git where the remote repository is located (i.e., the URL of the GitHub repo).

Simple Hand-Made Diagram:


[ Local Repository ] <---- Push/Pull ----> [ Remote Repository (GitHub) ]

Tasks

Task 1: Set Your Username and Email Address in Git

Before committing code, it’s important to associate your identity with the commits. Use the following commands to set up your Git user details:

git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"

Task 2: Create a Repository Named "DevOps" on GitHub and Push Local Commits

Here’s how you can complete the task:

  1. Create a repository named "DevOps" on GitHub:

    • Follow the steps mentioned above to create a repository.
  2. Create a Local Repository:

     mkdir DevOps
     cd DevOps
     git init
    
  3. Connect the Local Repository to GitHub:

     git remote add origin https://github.com/your-username/DevOps.git
    
  4. Create a New File:

     mkdir -p Devops/Git
     echo "This is Day-02 content" > Devops/Git/Day-02.txt
    
  5. Stage, Commit, and Push Your Changes:

     git add .
     git commit -m "Added Day-02 content"
     git push -u origin main
    

Now your code is pushed to GitHub and you can continue working on your project collaboratively.


By understanding Git and GitHub and following these practical steps, you are ready to streamline version control and collaborate with your team more efficiently.

0
Subscribe to my newsletter

Read articles from Faizan Shaikh directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Faizan Shaikh
Faizan Shaikh