Working with Remotes
Remote repositories are hosted on services like GitHub, GitLab, or Bitbucket. They enable collaboration and backup.
Example
# Add a remote
git remote add origin https://github.com/user/repo.git
# View remotes
git remote -v
# Push to remote
git push -u origin main
# Pull latest changes
git pull origin main
# Fetch without merging
git fetch origin Push, Pull, and Fetch
Push sends your commits to the remote. Pull downloads and merges remote changes. Fetch downloads without merging.
Example
# Push current branch
git push
# Push a new branch
git push -u origin feature-branch
# Pull (fetch + merge)
git pull
# Fetch only (see what's changed without merging)
git fetch
git log origin/main --oneline
# Pull with rebase (cleaner history)
git pull --rebase origin main 