Git
Remotes & Collaboration
A remote is a version of your repository hosted elsewhere (like GitHub). Remotes let you back up your work and collaborate with others.
Connecting to a remote
# Link your local repo to a remote named "origin"
git remote add origin https://github.com/user/repo.git
# Verify
git remote -v
# Push your branch and set it to track the remote
git push -u origin main
After -u (upstream) is set once, you can just use git push and git pull.
Syncing changes
# Download remote changes WITHOUT merging (safe to review)
git fetch
# Download AND merge into your current branch
git pull
💡
git pull = git fetch + git merge. Use fetch when you want to review before integrating; use pull for the everyday "get latest" flow.
The collaboration workflow
A typical team flow with pull requests:
# 1. Start from up-to-date main
git switch main
git pull
# 2. Create a feature branch
git switch -c feature/new-page
# 3. Work, commit, and push
git add .
git commit -m "Add new page"
git push -u origin feature/new-page
# 4. Open a Pull Request on GitHub for review
# 5. After approval, merge it into main
Pull Requests
A Pull Request (PR) proposes merging your branch into another. It's where code review, discussion, and automated checks (CI) happen before code reaches the main branch.
💡
Keep branches short-lived. The longer a branch lives, the harder it is to merge. Aim to merge within a day or two to avoid painful conflicts.
Watch & Learn
A recommended video to watch alongside this chapter.
More “Remotes & Collaboration” videos on YouTube