Local Git is great for tracking your own changes. But the real power comes from remote repositories—central hubs where teams collaborate. GitHub is the standard for DevOps teams, storing everything from application code to Terraform configurations. This lesson transforms you from a solo Git user into a collaborative team player.

1. Learning Objectives

By the end of this lesson, you will be able to:

  • Connect local repositories to GitHub with git remote add
  • Push commits to GitHub with git push
  • Pull changes from teammates with git pull
  • Clone existing repositories with git clone
  • Create and review Pull Requests on GitHub
  • Collaborate without overwriting others' work

2. Why This Matters

Real-world scenario: Your team of 5 DevOps engineers needs to manage Kubernetes manifests for 50 microservices. Without remote Git, you'd email files back and forth and constantly overwrite each other's work. With GitHub, you see who changed what, review changes before they're merged, and have a complete audit trail.

Key scenarios where remotes are essential:

  • CI/CD pipelines (GitHub Actions trigger on git push)
  • Infrastructure-as-code (Terraform state in Git)
  • Team collaboration (multiple engineers working together)
  • Backup and disaster recovery (cloud backup of your code)
  • Open source contribution (working with projects worldwide)

3. Core Concepts

What is a Remote?

A remote is a version of your repository hosted on the internet or network. GitHub, GitLab, and Bitbucket are popular remote hosting services. Your local repository can have multiple remotes (e.g., origin = GitHub, backup = GitLab).

Step 1: Create a Repository on GitHub

Do this first (via website):

  1. Go to github.com and sign up/login
  2. Click the '+' icon → 'New repository'
  3. Repository name: my-devops-project
  4. Description: 'Learning Git for DevOps'
  5. Keep it Public (or Private if you prefer)
  6. DO NOT initialize with README (we have local files)
  7. Click 'Create repository'

Step 2: Connect Local to Remote

# Add the remote (replace YOUR_USERNAME)
git remote add origin https://github.com/YOUR_USERNAME/my-devops-project.git

# Verify remote was added
git remote -v
# Output:
# origin  https://github.com/YOUR_USERNAME/my-devops-project.git (fetch)
# origin  https://github.com/YOUR_USERNAME/my-devops-project.git (push)

# Rename remote (if you made a typo)
git remote rename origin upstream

# Remove a remote
git remote remove origin
Connecting local repository to GitHub

Step 3: Push to GitHub

# Push main branch to GitHub
git push -u origin main

# The -u flag (set upstream) remembers the remote
# After this, you can just type 'git push'

# Output should show:
# Enumerating objects: 5, done.
# To https://github.com/YOUR_USERNAME/my-devops-project.git
#  * [new branch]      main -> main
# Branch 'main' set up to track remote branch 'main' from 'origin'.
Pushing your code to GitHub
kubectl get pods -w
$ git push -u origin main
Username for 'https://github.com': YOUR_USERNAME
Password:
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 8 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (5/5), 564 bytes | 564.00 KiB/s, done.
Total 5 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/YOUR_USERNAME/my-devops-project.git
* [new branch] main -> main
Branch 'main' set up to track remote branch 'main' from 'origin'.
Successful push to GitHub

Cloning: Downloading Existing Repositories

# Clone via HTTPS (requires authentication)
git clone https://github.com/username/repository.git

# Clone via SSH (recommended for teams)
git clone git@github.com:username/repository.git

# Clone into specific directory name
git clone https://github.com/username/repository.git my-folder

# Clone only the latest commit (shallow clone)
git clone --depth 1 https://github.com/username/repository.git

# Example: Clone a real DevOps project
git clone https://github.com/kubernetes/examples.git
cd examples
ls
Cloning repositories

Pulling: Getting Latest Changes

# Fetch changes without merging
git fetch origin

# Pull changes (fetch + merge automatically)
git pull origin main

# After setting upstream, just:
git pull

# Pull with rebase (cleaner history)
git pull --rebase

# If your teammate pushed changes:
# You need to pull before pushing
git pull
# Resolve any conflicts if they exist
git push
Getting changes from remote

The Collaboration Workflow

# === YOU (Developer A) ===
# Start work
git checkout main
git pull                    # Get latest changes
git checkout -b feature/new-thing
# Make changes...
git add .
git commit -m "Add new feature"
git push -u origin feature/new-thing

# === Now create Pull Request on GitHub ===

# === TEAMMATE (Developer B) ===
# Review code, approve, merge PR

# === YOU (Developer A) after merge ===
git checkout main
git pull                    # Get the merged code
git branch -d feature/new-thing  # Delete local branch
Complete team collaboration workflow

Pull Requests: The Heart of Collaboration

A Pull Request (PR) is how you propose changes on GitHub. It lets teammates review your code before it's merged.

How to create a Pull Request:

  1. Push your feature branch to GitHub (git push origin feature/name)
  2. Go to your repository on GitHub.com
  3. Click 'Pull Requests' tab → 'New Pull Request'
  4. Base: main ← Compare: feature/name
  5. Add title and description explaining your changes
  6. Click 'Create Pull Request'
  7. Request reviewers
  8. After approval, click 'Merge Pull Request'

4. Complete Project: Team Configuration Repository

# Project: Set up a shared repository for team configurations

# === Developer 1: Create repository ===
mkdir team-configs
cd team-configs
git init

echo "# Team Infrastructure Configs" > README.md
mkdir nginx terraform

echo "server {
    listen 80;
    server_name example.com;
    location / {
        proxy_pass http://app:3000;
    }
}" > nginx/default.conf

echo 'variable "environment" {
  default = "production"
}' > terraform/variables.tf

git add .
git commit -m "Initial commit: Add nginx and terraform configs"

# Create GitHub repo 'team-configs' via website, then:
git remote add origin https://github.com/YOUR_TEAM/team-configs.git
git push -u origin main

# === Developer 2: Clone and contribute ===
git clone https://github.com/YOUR_TEAM/team-configs.git
cd team-configs
git checkout -b feature/add-monitoring

mkdir prometheus
echo "global:
  scrape_interval: 15s
scrape_configs:
  - job_name: 'node'
    static_configs:
      - targets: ['localhost:9100']" > prometheus/prometheus.yml

git add .
git commit -m "Add Prometheus configuration"
git push -u origin feature/add-monitoring

# Create Pull Request on GitHub
# Team reviews, merges

# === Developer 1: Get updates ===
git checkout main
git pull
echo "✓ Got the new monitoring config!"
Real team collaboration example

5. Common Errors & Solutions

# Generate SSH key
ssh-keygen -t ed25519 -C "your_email@example.com"
# Press Enter for default location
# Enter passphrase (optional but recommended)

# Copy public key to clipboard
cat ~/.ssh/id_ed25519.pub

# Add to GitHub:
# Settings → SSH and GPG keys → New SSH key
# Paste public key

# Test connection
ssh -T git@github.com
# Output: Hi username! You've successfully authenticated.
Setting up SSH for password-less pushes

7. Summary Checklist

8. Next Steps

Next category: Python & Automation - Programming Fundamentals

You'll learn to:

  • Write Python scripts for automation
  • Work with files, APIs, and system commands
  • Build CLI tools for DevOps tasks
  • Create reusable Python modules

Gataya Med

DevOps Engineer & Backend Developer. Sharing insights on cloud, automation, and scalable systems.

Comments (0)

Sarah Chen January 20, 2025

This is exactly what I needed! The initContainer approach solved our migration issues completely. Thanks for the detailed guide!

Reply

Leave a Comment