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):
- Go to github.com and sign up/login
- Click the '+' icon → 'New repository'
- Repository name: my-devops-project
- Description: 'Learning Git for DevOps'
- Keep it Public (or Private if you prefer)
- DO NOT initialize with README (we have local files)
- 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
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'.
$ 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'.
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
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
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
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:
- Push your feature branch to GitHub (git push origin feature/name)
- Go to your repository on GitHub.com
- Click 'Pull Requests' tab → 'New Pull Request'
- Base: main ← Compare: feature/name
- Add title and description explaining your changes
- Click 'Create Pull Request'
- Request reviewers
- 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!"
5. Common Errors & Solutions
6. SSH Key Setup (Recommended for Teams)
# 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.
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
Comments (0)
This is exactly what I needed! The initContainer approach solved our migration issues completely. Thanks for the detailed guide!
ReplyLeave a Comment