Git Collaboration
Remote Repositories
A remote is a version of your repository hosted elsewhere (GitHub, GitLab, Bitbucket).Viewing Remotes
Adding Remotes
Cloning Repositories
Pushing Changes
Pulling Changes
Pull vs Fetch
| Command | What it does |
|---|---|
git fetch | Downloads changes but doesn’t merge |
git pull | Downloads and merges (fetch + merge) |
Working with Forks
Forking Workflow
1
Fork on GitHub
Click “Fork” button on the repository
2
Clone your fork
3
Add upstream remote
4
Keep fork updated
Pull Requests (PRs)
Pull requests are how you propose changes to a repository.Creating a Pull Request
PR Best Practices
Small PRs
Easier to review, faster to merge
Clear Description
Explain what and why, not just how
Link Issues
Reference related issues: “Fixes #123”
Update Branch
Keep PR branch updated with main
PR Template Example
Code Review
As a Reviewer
- ✅ “Consider using a Map here for O(1) lookup”
- ✅ “This could cause a race condition if…”
- ✅ “Great solution! Minor: variable name could be more descriptive”
- ❌ “This is wrong”
- ❌ “Why did you do it this way?”
- ❌ “I would have done it differently”
As an Author
Collaboration Workflows
Centralized Workflow
Feature Branch Workflow
Forking Workflow
Handling Common Scenarios
Syncing Fork with Upstream
Updating PR Branch
Resolving PR Conflicts
SSH vs HTTPS
HTTPS
Cons: Need to enter credentials (or use credential helper)
SSH
Cons: Requires SSH key setup
Setting Up SSH
Tags and Releases
Creating Tags
Semantic Versioning
Practical Examples
Example 1: Contributing to Open Source
Example 2: Team Feature Development
Troubleshooting
”Your branch is behind ‘origin/main’"
"Your branch has diverged"
"Permission denied (publickey)"
"Failed to push some refs”
Best Practices
Pull Before Push
Pull Before Push
Always get latest changes before pushing
Small, Focused PRs
Small, Focused PRs
- One feature/fix per PR
- Easier to review
- Faster to merge
Write Good PR Descriptions
Write Good PR Descriptions
- What changed
- Why it changed
- How to test
- Screenshots if UI changes
Review Code Thoughtfully
Review Code Thoughtfully
- Be constructive
- Ask questions
- Suggest improvements
- Approve when ready
Key Takeaways
- Remotes connect local and hosted repositories
- Pull requests enable code review
- Forks allow external contributions
- SSH keys simplify authentication
- Good collaboration requires communication
Next: Git Advanced Topics →