All chapters in this track
- 011. The Mental Model
- 022. Essential Setup
- 033. Core Daily Workflow
- 044. Branching
- 055. Merging & Conflict Resolution
- 066. Rebasing
- 077. Remote Repositories
- 088. Stashing
- 099. Undoing Things
- 1010. Tagging & Versioning
- 1111. Cherry-Pick
- 1212. Git Bisect & Blame
- 1313. Git Hooks
- 1414. Submodules
- 1515. Team Workflows
- 1616. Power Commands & Aliases
- 1717. Reflog: The Safety Net
- 1818. Practice Tasks
- 19Quick Reference Cheatsheet
Chapter 7 of 19
7. Remote Repositories
# View remotes
git remote -v
# Add / rename / remove
git remote add origin https://github.com/user/repo.git
git remote rename origin upstream
git remote remove old-remote
# Push
git push origin main # push main to origin
git push -u origin feature/login # push + set upstream tracking
git push # push to tracked remote (after -u)
git push origin --delete feature/old # delete remote branch
# Fetch & pull
git fetch origin # download changes, don't merge
git fetch --all # fetch all remotes
git pull # fetch + merge (or rebase if configured)
git pull origin main # explicit
git pull --rebase # fetch + rebase (cleaner history)
# Track remote branches
git branch --set-upstream-to=origin/main main
Fetch vs Pull
| Command | What happens |
|---|---|
git fetch | Downloads remote changes into origin/branch. Your local branch is untouched. You review before merging. |
git pull | fetch + merge (or rebase). Automatic. Less control. |
Best practice: use fetch + manual merge/rebase on shared branches.
Useful remote inspection
git log origin/main..HEAD # local commits not yet pushed
git diff origin/main # diff between remote and local
git branch -r # list remote branches