Back to Home
Git
Remote repository operations with Git: fetch, pull, push and merge workflow
fetchpullpushmergeremoteupstreamworkflow
Git Remote Workflow
Working with remote repositories: essential commands and workflow.
Fetch - Download Remote Changes
# Download all remote changes (does not merge)
git fetch origin
# Fetch specific branch
git fetch origin main
# Fetch from all remotes
git fetch --all
# Clean up deleted remote branches
git fetch --prune
Pull - Download and Merge
# Fetch + merge (default behavior)
git pull origin main
# Fetch + rebase (cleaner commit history)
git pull --rebase origin main
# Pull all branches
git pull --all
# Pull current branch (if upstream is set)
git pull
Push - Send Changes
# Push current branch
git push origin main
# Push new branch and set upstream
git push -u origin feature-branch
# Short push (if upstream is set)
git push
# Push all branches
git push --all origin
# Push tags
git push origin --tags
git push origin v1.0.0
# Force push (use with caution!)
git push --force-with-lease origin feature-branch
Merge Strategies
# Merge feature branch into main
git checkout main
git pull origin main
git merge feature-branch
# No fast-forward merge (creates merge commit)
git merge --no-ff feature-branch
# Squash merge (combines all commits into one)
git merge --squash feature-branch
git commit -m "feat: feature description"
# Abort merge
git merge --abort
Typical Development Workflow
# 1. Update main branch
git checkout main
git pull origin main
# 2. Create feature branch
git checkout -b feature/new-feature
# 3. Make changes and commit
git add .
git commit -m "feat: add new feature"
# 4. Get latest updates from main
git fetch origin main
git rebase origin/main
# 5. Push
git push -u origin feature/new-feature
# 6. Clean up after PR merge
git checkout main
git pull origin main
git branch -d feature/new-feature