Git
Manage Remotes and Push Pull
Add, change, and interact with remote repositories in Git.
By EZ4Code Team
remotepushintermediate
Code
# Add a remote
git remote add origin https://github.com/user/repo.git
# List remotes
git remote -v
# Change remote URL
git remote set-url origin [email protected]:user/repo.git
# Fetch from remote (no merge)
git fetch origin
git fetch --all --prune
# Pull = fetch + merge
git pull origin main
git pull --rebase origin main # rebase instead of merge
# Push
git push origin main
git push --force-with-lease # safer force push
# Remove a remote
git remote remove origin
# Track a remote branch
git switch -c feature origin/featureExplanation
Covers remote repository management: adding remotes, listing them, changing URLs, and syncing with fetch, pull, and push. fetch downloads changes without merging, while pull = fetch + merge; use --rebase to keep history linear. --force-with-lease is a safer alternative to --force when rewriting shared branches.