Remotes are versions of your repository hosted elsewhere (e.g., GitHub). git push uploads your commits to the remote; git pull downloads remote commits and merges them into your current branch. git fetch downloads without merging.
Git
Beginner
10 min read
git remote, push, and pull
Example
# View remote connections:
git remote -v
# origin https://github.com/jane/my-repo.git (fetch)
# origin https://github.com/jane/my-repo.git (push)
# Add a remote:
git remote add origin https://github.com/jane/my-repo.git
# Push to a remote branch (and set upstream tracking):
git push -u origin main
# After -u, you can just use: git push
# Push a specific local branch to remote:
git push origin feature/login
# Pull: fetch + merge in one command:
git pull
# Fetch only (no merge):
git fetch origin
# See what fetch downloaded:
git log origin/main --oneline
# Merge fetched changes manually:
git merge origin/main
# Pull with rebase instead of merge:
git pull --rebase
# Delete a remote branch:
git push origin --delete feature/old-feature
# Rename a remote:
git remote rename origin upstream