Understanding Git & GitHub: A DevOps Perspective

Kanav GatheKanav Gathe
3 min read

1. What is Git and Why is it Important?

Git is a distributed version control system that helps developers track changes in their code over time. Think of it as a time machine for your code that remembers every change you make and allows you to:

  • Track who made what changes and when

  • Revert to previous versions if something goes wrong

  • Work on different features simultaneously without interfering with each other

  • Collaborate with team members efficiently

Git is crucial in DevOps because it enables:

  • Continuous Integration/Continuous Deployment (CI/CD)

  • Code review processes

  • Team collaboration

  • Project history maintenance

  • Bug tracking and resolution

2. Main Branch vs Master Branch

The difference between Main and Master branch is primarily terminology-based, but it reflects an important industry shift:

  • Master Branch: The traditional default name for the primary branch in Git

  • Main Branch: The new industry-standard name that's being adopted for inclusivity

Functionally, they serve the same purpose as the default/primary branch of your repository. GitHub and many organizations have moved to using "main" as the default branch name since October 2020 to promote more inclusive language.

3. Git vs GitHub: Understanding the Difference

Think of it this way:

  • Git is like your local workshop where you build and track changes to your project

  • GitHub is like a social workshop hosting service where you can share your work and collaborate with others

Key differences:

  • Git is the version control system that runs locally on your machine

  • GitHub is a cloud-based hosting service that lets you manage Git repositories

  • Git can work completely offline; GitHub requires internet connection

  • Git handles version control; GitHub adds collaboration features like pull requests, issues, and discussions

4. Creating a New Repository on GitHub

The process is straightforward:

  1. Log into GitHub

  2. Click the "+" icon in the top right corner

  3. Select "New repository"

  4. Fill in the details:

    • Repository name

    • Description (optional)

    • Public/Private setting

    • Initialize with README option (optional but preferred)

    • License selection (if needed)

  5. Click "Create repository"

5. Local vs Remote Repository and Connecting Them

Local Repository:

  • Exists on your computer

  • Contains all project files and Git history

  • Where you make changes and commit them

  • Can work offline

Remote Repository:

  • Hosted on a server (like GitHub)

  • Serves as a centralized location for team collaboration

  • Accessible to all team members

  • Requires internet connection to sync

Connecting Local to Remote:

# Initialize a local repository
git init

# Add your files to staging(all)
git add .

# Add your file to staging(selected)
git add filename

# Commit your files
git commit -m "Initial commit"

# Add remote repository URL
git remote add origin <repository-URL>

# Push your code to remote
git push -u origin main

In the diagram above, you can see how these components interact. The Working Directory is where you make changes, the Staging Area is where you prepare changes for commit, and the Local Repository stores your commit history. The Remote Repository on GitHub serves as the central point for collaboration.

Understanding these concepts is crucial for DevOps engineers as they form the foundation of version control and collaboration in modern software development. Git and GitHub are essential tools that enable efficient team collaboration, code management, and deployment processes in the DevOps pipeline.

0
Subscribe to my newsletter

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

Written by

Kanav Gathe
Kanav Gathe