Remote
Connect local repositories to remotes, push, pull, and track branches
Overview
Remotes are named references to other repositories—usually origin on GitHub or GitLab. Push uploads commits; pull fetches and integrates remote changes. Set upstream tracking so git push and git pull know the default remote branch.
Syntax / Usage
# List remotes
git remote -v
# Add remote
git remote add origin git@github.com:user/repo.git
# Change remote URL
git remote set-url origin git@github.com:user/new-repo.git
# Fetch without merging
git fetch origin
# Pull (fetch + merge/rebase)
git pull origin main
git pull --rebase origin main
# Push
git push origin feature/login
git push -u origin feature/login # set upstream
# Delete remote branch
git push origin --delete feature/old
Examples
First push of a new branch:
git switch -c feature/docs
git commit -m "docs: add API guide"
git push -u origin feature/docs
Update fork from upstream:
git remote add upstream git@github.com:original/repo.git
git fetch upstream
git switch main
git merge upstream/main
git push origin main
Common Mistakes
- Pushing to wrong remote or branch—verify with
git remote -vandgit branch -vv - Force pushing to shared branches (
main) and overwriting teammates' work - HTTPS vs SSH URL confusion causing auth failures
- Pulling without committing or stashing local changes first
See Also
clone branch commit merge