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 repository
  • git push — upload commits to remote
  • git pull — download and merge remote changes
  • git fetch — download remote changes (don't merge)

Origin

When you clone a repo, Git names the remote "origin" by default.

GitHub Workflow

  1. Fork the repository (your copy)
  2. Clone to local machine
  3. Create a feature branch
  4. Push branch to GitHub
  5. Open a Pull Request
  6. Get code review
  7. 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/main
Try it yourself — BASH