Collaborating on GitHub: A DevOps Engineer’s Guide

Hello, my fellow DevOps Engineers! Today, we’re diving into a crucial topic—GitHub! Whether you’re a Developer or a DevOps Engineer, GitHub is where all the magic happens—code storage, collaboration, version control, and reviews. Mastering GitHub is essential for efficient teamwork, CI/CD pipelines, and seamless deployments.

So, without further ado, let’s jump right in!


What is a GitHub Repository?

A GitHub repository (repo) is a storage space for your code, files, and version history. It allows multiple developers to work together using Git.

🔹 Local Repository – Exists on your computer.
🔹 Remote Repository – Exists on GitHub, accessible from anywhere.

💡 A GitHub repo is like a cloud-based Git project that enables easy sharing, collaboration, and version control.


Why Do We Need a GitHub Repository?

A GitHub repo helps with:

  • Version control – Track changes over time.

  • Collaboration – Multiple developers can work together.

  • CI/CD Integration – Automate testing & deployments.

  • Backup & Security – Store code safely in the cloud.

  • Open Source Contributions – Share your projects with the world.


  • Free and easy to use

  • Supports private & public repositories

  • Seamless integration with DevOps tools (Jenkins, Docker, Terraform, etc.)

  • Pull Request (PR) workflows for better collaboration

  • GitHub Actions for CI/CD automation


Creating a GitHub Account & Logging In

Step 1: Open GitHub in Your Browser

Go to 👉 GitHub

Step 2: Sign Up for an Account

1️⃣ Click "Sign up"
2️⃣ Enter Username, Email, and Password
3️⃣ Click "Create account"
4️⃣ Verify your email and set up your profile.

Step 3: Log In

Once signed up, log in anytime by entering your email and password.


Creating a New Repository on GitHub

Step 1: Create a Repository

  1. Click +New repository.

  2. Name your repo (e.g., devops_git_demo).

  3. Add a description: "Repository for DevOps GitHub series of DevOpsVoyage blog".

  4. Select Public (or Private).

  5. Check Add a README fileCreate repository.


Cloning the Repository in VS Code

Step 1: Copy the Repository URL

  1. On your GitHub repo page, click Code → Copy the HTTPS URL (e.g., https://github.com/RajGaik26/devops_git_demo.git).

Step 2: Clone in VS Code

1️⃣ Open VS Code and open the terminal.
2️⃣ Clone the repo into VS Code:

git clone https://github.com/RajGaik26/devops_git_demo.git

3️⃣ Move into the repo directory:

cd devops_git_demo/


Creating & Editing Files in VS Code

Step 1: Create a New File (Python Example)

1️⃣ Right Click on "Explorer" (Ctrl + Shift + E)
2️⃣ Click "New File", name anything you wish:

print("Hello, DevOps Engineers!")

3️⃣ Save the file (Ctrl + S)


Adding, Committing, and Pushing Changes

Step 1: Check File Status

git status

You will see hello.py as untracked (red text).

Step 2: Add the File to Staging

git add hello.py

The file is now staged (green text).

Step 3: Commit the Changes

git commit -m "Add hello.py file"

Your changes are now saved locally but have not yet been uploaded to GitHub.

Step 4: Push the Code to GitHub

git push origin main

🎉 Your code is now on GitHub!


Pulling Changes from GitHub

If your teammate adds a new file on GitHub, you should pull updates before making further changes.

git pull origin main

This fetches and merges the latest updates.


Working with Branches

Step 1: Create a New Branch

git checkout -b feature-branch

You are now on a new branch called feature-branch.

Step 2: Add a New File (Calculator Example)

1️⃣ Create a new file calculator.py and add:

def add(a, b):
    return a + b

def subtract(a, b):
    return a - b

def multiply(a, b):
    return a * b

def divide(a, b):
    if b == 0:
        return "Cannot divide by zero!"
    return a / b

print("Simple Calculator")
print("-----------------")

while True:
    print("\nSelect operation:")
    print("1. Add")
    print("2. Subtract")
    print("3. Multiply")
    print("4. Divide")
    print("5. Exit")

    choice = input("Enter choice (1/2/3/4/5): ")

    if choice == '5':
        print("Calculator exited.")
        break

    if choice not in ['1', '2', '3', '4']:
        print("Invalid input! Please try again.")
        continue

    try:
        num1 = float(input("Enter first number: "))
        num2 = float(input("Enter second number: "))
    except ValueError:
        print("Invalid input! Please enter numbers only.")
        continue

    result = None
    if choice == '1':
        result = add(num1, num2)
    elif choice == '2':
        result = subtract(num1, num2)
    elif choice == '3':
        result = multiply(num1, num2)
    elif choice == '4':
        result = divide(num1, num2)

    print(f"\nResult: {result}")

2️⃣ Save the file (Ctrl + S)

Step 3: Add, Commit, and Push the Branch

git add calculator.py
git commit -m "Add Calculator file"
git push origin feature-branch

🎉 Your code is now on GitHub!


Pull Requests (PRs) for Code Reviews

DevOps Workflow Example

Scenario: A teammate adds a security patch to your Terraform config.

  1. Create a Feature Branch:

    • In VS Code’s bottom panel, click the branch name (e.g., main) → Create new branchfeature/security-patch.
  2. Make Changes:

    • Update main.tf to use a newer AMI (Example):

        ami = "ami-0ff8a91507f77f867"
      
  3. Commit & Push the Branch:

    • Stage changes → Commit → Push (VS Code will prompt to publish the branch).
  4. Open a Pull Request:

    • Go to your GitHub repo → Pull RequestsNew Pull Request.

    • Set base: main and compare: feature/security-patch.

    • Add a reviewer and click Create PR.

  5. Merge After Approval:

    • Once reviewed, click Merge pull requestConfirm merge.

Merging the PR and Deleting the Branch

Once the PR is approved:

git checkout main
git pull origin main  # Ensure the latest changes are fetched
git merge feature/security-patch
git push origin main

After merging, delete the branch:

git branch -d feature/security-patch
git push origin --delete feature/security-patch

Team Workflows: Forking vs. Branching

Forking Strategy

  1. Fork the Repository:

    • Click Fork on the repo page to create your copy (e.g., for open-source contributions).
  2. Clone & Push:

    • Work on your fork → Submit PRs to the original repo.

Branching Strategy

  1. Feature Branches:

    • Prefix branches with feature/, bugfix/, or hotfix/ (e.g., feature/ansible-role).
  2. Protected Branches:

    • In GitHub repo settings → Branches → Add rule for main to require PR approvals.

DevOps Best Practices on GitHub

  1. GitHub Actions for CI/CD:

    • Add a .github/workflows/deploy.yml file to automate Terraform deployments.
  2. Secrets Management:

    • Store API keys/AWS credentials in Settings → Secrets → Actions.
  3. Code Scanning:

    • Enable Dependabot to detect vulnerabilities in dependencies.

Conclusion

Cloning, branching, and committing is now easy inside VS Code!
Push and pull operations ensure you always have the latest code.
PRs help you collaborate effectively in DevOps workflows.
Forking lets you contribute to external projects.


Finally, we’re done! Give yourselves a round of applause—you’ve earned it! What an incredible ride this has been. Let’s take a moment to reflect on everything we’ve covered in this Git and GitHub series:

Introduction to Git: Version Control for DevOps Engineers
Installing Git and Writing Your First Command: A Beginner’s Guide
Git Branching and Merging: A Practical Guide for DevOps
Advanced Git Workflows for DevOps: Stash, Rebase, Diff, and Cherry-Pick
Collaborating on GitHub: A DevOps Engineer’s Guide


These topics have set you on the path to mastering Git and GitHub, but remember—learning doesn’t stop here! The key to truly becoming a pro is consistent practice. Keep using Git in your projects, experiment with different workflows, and push yourself to explore more advanced features.

And guess what? We’re just getting started! While this series may be ending, the learning never stops! A new journey begins as we dive into our next series: "Networking"

As they say, New day, new topic! And trust me, you don’t want to miss this one. Stay tuned.

Until next time, keep coding, automating, and advancing in DevOps! 😁

Peace out ✌️

0
Subscribe to my newsletter

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

Written by

Rajratan Gaikwad
Rajratan Gaikwad

I write about the art and adventure of DevOps, making complex topics in CI/CD, Cloud Automation, Infrastructure as Code, and Monitoring approachable and fun. Join me on my DevOps Voyage, where each post unpacks real-world challenges, explores best practices, and dives deep into the world of modern DevOps—one journey at a time!