Vasu Patel logoVasu Patel
← Git Mastery
All chapters in this track
  1. 011. The Mental Model
  2. 022. Essential Setup
  3. 033. Core Daily Workflow
  4. 044. Branching
  5. 055. Merging & Conflict Resolution
  6. 066. Rebasing
  7. 077. Remote Repositories
  8. 088. Stashing
  9. 099. Undoing Things
  10. 1010. Tagging & Versioning
  11. 1111. Cherry-Pick
  12. 1212. Git Bisect & Blame
  13. 1313. Git Hooks
  14. 1414. Submodules
  15. 1515. Team Workflows
  16. 1616. Power Commands & Aliases
  17. 1717. Reflog: The Safety Net
  18. 1818. Practice Tasks
  19. 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

CommandWhat happens
git fetchDownloads remote changes into origin/branch. Your local branch is untouched. You review before merging.
git pullfetch + 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