Collaboration
Remote Repositories
Work with remote repositories on GitHub, push your code, and collaborate with others.
Remote Repositories
A remote is a version of your repository hosted somewhere accessible to others — GitHub, GitLab, Bitbucket, or a private server.
Common Remote Operations
git clone— download a repositorygit push— upload commits to remotegit pull— download and merge remote changesgit fetch— download remote changes (don't merge)
Origin
When you clone a repo, Git names the remote "origin" by default.
GitHub Workflow
- Fork the repository (your copy)
- Clone to local machine
- Create a feature branch
- Push branch to GitHub
- Open a Pull Request
- Get code review
- Merge into main
Example
bash
# Clone a repository
git clone https://github.com/user/repo.git
git clone https://github.com/user/repo.git my-folder
# View remotes
git remote -v
# Add a remote
git remote add origin https://github.com/user/repo.git
# Push to remote
git push origin main
git push origin feature/my-feature
# Push and set upstream (first push of a branch)
git push -u origin feature/my-feature
# After this, just use: git push
# Pull (fetch + merge)
git pull origin main
git pull # uses default (origin + current branch)
# Fetch (download but don't merge)
git fetch origin
git diff main origin/main # see what changed
# Pull Request workflow
git switch -c feature/new-login
# ... make changes and commits ...
git push -u origin feature/new-login
# Then open GitHub and create a Pull Request
# Sync your fork with the original repo
git remote add upstream https://github.com/original/repo.git
git fetch upstream
git merge upstream/mainTry it yourself — BASH