Working with Remotes

Remotes connect your local repo to a server (GitHub, GitLab, etc.) for collaboration.

Connecting to a remote

bash
# Add a remote
git remote add origin https://github.com/user/repo.git

# See your remotes
git remote -v

Push and pull

bash
# Push your branch to the remote
git push origin main

# Set upstream (do this once per branch)
git push -u origin main

# Pull latest changes from the remote
git pull origin main

The Pull Request workflow

1. Create a feature branch locally

2. Push it to the remote

3. Open a Pull Request on GitHub

4. Team reviews the code

5. Merge when approved

bash
git checkout -b feature/search
# ... make changes ...
git add . && git commit -m "Add search functionality"
git push -u origin feature/search
# Then open PR on GitHub

Keeping your branch up to date

bash
# Fetch latest from remote
git fetch origin

# Rebase your branch on top of main
git rebase origin/main

This keeps your branch history clean and avoids unnecessary merge commits.