Git Collaboration - Working with Remote Repositories
Part of Git Essentials Series
This is article 2 of the Git Essentials series. If you haven't mastered local repositories yet, start with Git Basics first.
Your teammate just shared a repository link: "Here's the monitoring scripts repo - clone it and add your disk space check." You stare at the URL. Clone? Where does the code even go? How do you get your changes back to the team?
This is the reality of professional platform engineering - your scripts and infrastructure code live on shared repositories (GitHub, GitLab, Bitbucket), not just your laptop. Collaboration isn't optional; it's how the job works.
What Are Remote Repositories?
A remote repository is a version of your project hosted on a server (GitHub, GitLab, your company's Git server). Think of it as the "source of truth" that your team syncs with.
Why remote repositories matter for platform engineers:
- Collaboration - Multiple people can work on the same scripts/infrastructure code
- Backup - Your code exists on a server, not just your laptop
- Code review - Teammates can review changes before they go to production
- CI/CD integration - Automated testing and deployment when you push code
- Audit trail - Complete history of who changed what and when
The workflow:
graph TD
A[Remote Repository<br/>GitHub/GitLab] -->|git clone| B[Your Local Copy]
B -->|git add + commit| C[Local Changes]
C -->|git push| A
A -->|git pull| B
style A fill:#2f855a,stroke:#cbd5e0,stroke-width:2px,color:#fff
style B fill:#2d3748,stroke:#cbd5e0,stroke-width:2px,color:#fff
style C fill:#d69e2e,stroke:#cbd5e0,stroke-width:2px,color:#fff
Getting Started: Two Common Scenarios
Platform engineers encounter two main scenarios with remote repositories:
The situation: Your team already has a repository with scripts/configs. You need to get the code and start contributing.
What you do: Clone the repository to get a local copy.
| Clone an Existing Repository | |
|---|---|
- Downloads the entire repository including all history
- Navigate into the cloned directory
- See all the files - you now have a complete working copy
Key insight: clone creates a new directory with the repository name. You get everything: files, history, branches.
The situation: You've been working on scripts locally (using Git Basics). Now you want to share them with your team.
What you do: Create a remote repository and push your local work to it.
| Push Local Repository to Remote | |
|---|---|
- Link your local repo to the remote repository
- Ensure your branch is named "main" (modern convention)
- Push your code and set upstream tracking (initial push only - see warning below)
After This Initial Push
This is a one-time setup to get your code on the remote. Once teammates join, always work on branches and use pull requests to merge to main. See the Daily Collaboration Workflow section below.
Understanding Clone, Pull, and Push
Three commands control collaboration:
| Command | Direction | What It Does | When You Use It |
|---|---|---|---|
git clone |
Remote → Local | Downloads entire repository for first time | Joining a new project |
git pull |
Remote → Local | Updates your local copy with team's changes | Morning sync, before starting work |
git push |
Local → Remote | Sends your commits to the remote | Sharing your completed work |
Setting Up Remote Repositories
Step 1: Create repository on GitHub
- Go to github.com and click "New repository"
- Name it (e.g.,
ops-scripts) - Choose public or private
- Don't initialize with README (you already have local commits)
- Click "Create repository"
Step 2: Link your local repository
| Connect to GitHub | |
|---|---|
SSH vs HTTPS: Use SSH URLs (git@github.com:...) for passwordless authentication with SSH keys. HTTPS URLs require credentials every push.
Step 1: Create project on GitLab
- Go to gitlab.com and click "New project"
- Choose "Create blank project"
- Name it and set visibility (public/private)
- Uncheck "Initialize repository with a README"
- Click "Create project"
Step 2: Link your local repository
Your company likely has:
- GitHub Enterprise (self-hosted GitHub)
- Self-hosted GitLab
- Bitbucket Server
- Azure DevOps Repos
- AWS CodeCommit
The process is the same:
| Connect to Company Git Server | |
|---|---|
Ask your team: What's the Git server URL? Do you need VPN access? Are there naming conventions?
Daily Collaboration Workflow
Professional collaboration with Git follows a rhythm: sync main, create branch, work, commit, push branch. Here's the visual workflow:
graph TD
A[Sync main<br/>git pull origin main] --> B[Create your branch<br/>git checkout -b feature/name]
B --> C[Work and commit<br/>Edit files, git add, git commit]
C --> D[Push your branch<br/>git push origin feature/name]
D --> E[Open Pull Request<br/>On GitHub/GitLab]
E --> F[Code Review<br/>Teammates review]
F --> G[Merge to main<br/>PR approved and merged]
G -.-> A
style A fill:#2d3748,stroke:#cbd5e0,stroke-width:2px,color:#fff
style B fill:#2d3748,stroke:#cbd5e0,stroke-width:2px,color:#fff
style C fill:#d69e2e,stroke:#cbd5e0,stroke-width:2px,color:#fff
style D fill:#2d3748,stroke:#cbd5e0,stroke-width:2px,color:#fff
style E fill:#4a5568,stroke:#cbd5e0,stroke-width:2px,color:#fff
style F fill:#4a5568,stroke:#cbd5e0,stroke-width:2px,color:#fff
style G fill:#2f855a,stroke:#cbd5e0,stroke-width:2px,color:#fff
Never Commit Directly to Main
In professional environments, main is protected. You work on your own branch and merge to main via pull requests (covered in Git Workflows - coming soon). Direct commits to main are bad practice.
Morning: Start with a Clean Sync
Before you touch any code, get the latest changes from your team and create a branch for your work.
| Morning: Sync and Create Branch | |
|---|---|
- Switch to main branch
- Get latest changes from the team
- Create a new branch for your work (branch names often use
feature/,fix/, orchore/prefixes)
What happens: Git fetches commits from the remote and automatically merges them into your local branch. If there are no conflicts, you're ready to work. If there are conflicts, Git will tell you which files need manual resolution.
Output you'll see:
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (3/3), done.
Unpacking objects: 100% (5/5), done.
From github.com:company/ops-scripts
abc1234..def5678 main -> origin/main
Updating abc1234..def5678
Fast-forward
backup.sh | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
This tells you your teammate modified backup.sh with 5 changes.
During the Day: Work on Your Branch
Now you can work on your changes. You're on your own branch (feature/disk-monitoring), so you can commit freely without affecting the team's main branch.
| During the Day: Make Changes | |
|---|---|
- Shows which branch you're on (should show
* feature/disk-monitoring) - Use the same review workflow from Git Basics - status, diff, add, commit
Pro tip for teams: Commit more frequently than you would solo. Small, focused commits ("Add monitoring function" → "Add threshold logic" → "Add alerts") are easier for teammates to review than one giant "Add disk monitoring" commit.
End of Day: Push Your Branch
When you're ready to share your work, push your branch to the remote repository. Your teammates can then review it via a pull request before it gets merged to main.
| End of Day: Push Your Branch | |
|---|---|
- Pushes your branch to the remote repository;
-usets up tracking so future pushes can use justgit push
What happens next: After pushing your branch:
- Open a pull request on GitHub/GitLab/etc.
- Teammates review your code
- Once approved, the PR gets merged to
main - You delete your branch and start a new one for the next task
We'll cover pull requests in detail in Git Workflows** (coming soon) - for now, just know that pushing your branch is the first step toward getting your code into main.
The Complete Daily Rhythm
Here's the full workflow on one screen:
Key habits:
- Always work on a branch - Never commit directly to
main - Sync main before creating branch - Start with the latest code
- Commit often - Small, focused commits are better
- Push your branch regularly - Backs up your work to the remote
- Clear commit messages - Your teammates (and future you) will thank you
- Use pull requests to merge to main - Covered in Git Workflows (coming soon)
Common Collaboration Patterns
Start every day with git pull:
| Daily Standup Routine | |
|---|---|
Why this matters: Prevents working on outdated code. You'll know immediately if teammates changed files you're planning to edit.
Someone broke the deployment script. Who was it? Use the git log and git blame commands from Git Basics, but now for team investigation:
Am I ahead or behind the team?
- Updates remote tracking info (doesn't change your files)
- Shows if you're ahead/behind/diverged from origin/main
Example output:
Understanding Remote Tracking
When you clone or push with -u, Git sets up remote tracking:
| See Remote Configuration | |
|---|---|
- Shows all remote repositories linked to your local repo
- Shows which remote branch your local branch tracks
What -u does in git push -u origin main:
- Sets
origin/mainas the "upstream" for your localmainbranch - After this, you can use just
git pushinstead ofgit push origin main - Git knows where to push and pull from automatically
Avoiding Common Mistakes
-
Don't Push Broken Code
The problem: Pushing code that doesn't work breaks your teammates' environments.
The solution: Test locally before pushing.
-
Don't Push Secrets
Setup: Git Basics covers .gitignore configuration - set that up BEFORE pushing.
Pre-push check: Once you're collaborating with a team, add this to your routine:
Pre-Push Secret Check If you accidentally pushed secrets: Rotate the credentials immediately. Once in remote history, deletion doesn't help - teammates already pulled it.
-
Always Pull Before Push
The problem: If you push without pulling first and teammates changed the same files, you'll get rejected.
Error you'll see:
The fix:
When Things Go Wrong
Scenario: "I pulled and now there are conflicts"
You'll see:
Auto-merging monitoring.sh
CONFLICT (content): Merge conflict in monitoring.sh
Automatic merge failed; fix conflicts and then commit the result.
What this means: You and a teammate changed the same lines. Git can't automatically merge. This conflict often happens when multiple changes occur at the same level of Git's internal tree structure.
Quick resolution (we'll cover this deeply in Git Efficiency):
- Open the file - Git marks conflicts with
<<<<<<<,=======,>>>>>>> - Edit to keep the correct version (yours, theirs, or combination)
- Remove the conflict markers
git add monitoring.shgit commit -m "Merge remote changes"git push origin main
Scenario: "I pushed and realized I made a mistake"
Option 1: Fix it with a new commit (recommended)
# Fix the mistake
vim monitoring.sh
git add monitoring.sh
git commit -m "Fix threshold logic in monitoring script"
git push origin main
Option 2: Revert the commit (creates inverse commit)
git log --oneline # Find the bad commit hash
git revert abc1234 # Creates new commit that undoes it
git push origin main
Don't use git push --force - This can overwrite teammates' work. Only force-push if you absolutely know what you're doing and have coordinated with your team.
Practice Problems
Practice Problem 1: Cloning and Exploring
You're joining a new team. They gave you the repository URL: git@github.com:company/ansible-playbooks.git
Tasks:
1. Clone the repository
2. List all files
3. See the last 5 commits
4. Find out who last modified webserver.yml
Solution
| Clone and Explore Repository | |
|---|---|
Practice Problem 2: Daily Workflow
You're working on a script called backup.sh. Your teammate just told you they pushed changes to main this morning.
Tasks: 1. Sync main with the latest changes 2. Create a branch for your work 3. Make your changes to the file 4. Commit and push your branch
Solution
Practice Problem 3: Checking Remote Status
You've made 3 local commits but haven't pushed yet. You want to know: 1. Are you ahead or behind the remote? 2. What commits haven't been pushed yet?
Solution
| Check Remote Status | |
|---|---|
Key Takeaways
| Concept | Command | When to Use |
|---|---|---|
| Clone | git clone <url> |
First time getting a repository |
| Branch | git checkout -b feature/name |
Create branch for your work |
| Pull | git pull origin main |
Sync main with team's latest changes |
| Push | git push origin feature/name |
Share your branch with team |
| Remote | git remote -v |
See configured remote repositories |
| Fetch | git fetch origin |
Update remote tracking (doesn't change files) |
| Status | git status |
Check if ahead/behind remote |
Quick Reference
Further Reading
Official Documentation
- Pro Git: Working with Remotes - Comprehensive guide to remote repositories
- GitHub Docs: Getting Started - GitHub-specific workflows
Platform-Specific Guides
- GitHub Flow - Simple branch-based workflow
- GitLab Flow - GitLab's recommended workflow
- Atlassian Git Tutorials - Excellent collaboration guides
Team Collaboration
- Git Workflows (coming soon) - Advanced collaboration patterns (feature branches, pull requests)
- Code Review Best Practices - Google's code review guide
Troubleshooting
- Oh Shit, Git!?! - Common Git mistakes and how to fix them
- Git Flight Rules - What to do when things go wrong
What's Next: You now know how to collaborate with Git. For advanced workflows like feature branches, pull requests, and conflict resolution, continue to Git Workflows (coming soon).