Git
05 / 06

Remote Workflows

Git Remote Workflows

Working with remote repositories is essential for team collaboration. Understanding how fetch, pull, and push interact with remote-tracking branches prevents data loss and merge conflicts.

Managing Remotes

# View remotes
git remote
git remote -v                    # Show URLs
git remote show origin           # Detailed info about a remote

# Add / rename / remove remotes
git remote add origin https://github.com/user/repo.git
git remote add upstream https://github.com/original/repo.git
git remote rename origin old-origin
git remote remove upstream

# Change remote URL
git remote set-url origin https://github.com/user/new-repo.git
git remote set-url origin git@github.com:user/repo.git  # Switch to SSH

Fetch, Pull & Push

git fetch downloads remote changes without merging them. git pull fetches and merges. git push uploads your local commits to the remote. Understanding the difference prevents accidental overwrites.

# Fetch - download remote changes, don't merge
git fetch origin
git fetch --all              # Fetch all remotes
git fetch origin main        # Fetch specific branch
git fetch --prune            # Remove stale remote-tracking branches

# Pull - fetch + merge (or rebase)
git pull
git pull origin main
git pull --rebase            # Rebase instead of merge
git pull --rebase=interactive
git pull --ff-only           # Fail if merge commit would be created

# Push
git push
git push origin main
git push -u origin feature-branch   # Set upstream tracking
git push --force-with-lease          # Safer force push (checks remote state)
git push origin --delete feature-branch  # Delete remote branch
git push --tags                          # Push all tags
git push origin v1.0.0                   # Push specific tag

# Tracking branches
git branch -u origin/main main           # Set upstream for existing branch
git branch --set-upstream-to=origin/feature feature

Forking & Upstream Sync

When contributing to open source, you fork the repo, make changes in your fork, then submit a pull request. Keeping your fork in sync with the original (upstream) requires a consistent workflow.

# Fork workflow - initial setup
git clone https://github.com/YOUR_USERNAME/repo.git
cd repo
git remote add upstream https://github.com/ORIGINAL_OWNER/repo.git
git remote -v   # Verify: origin = your fork, upstream = original

# Sync fork with upstream
git fetch upstream
git checkout main
git merge upstream/main
# Or in one step:
git pull upstream main

# Push synced main to your fork
git push origin main

# Work on a feature branch from up-to-date main
git checkout -b fix/issue-123
# ... make changes ...
git push origin fix/issue-123
# Then open pull request on GitHub

Tags & Releases

# List tags
git tag
git tag -l "v1.*"           # Filter by pattern

# Create tags
git tag v1.0.0              # Lightweight tag
git tag -a v1.0.0 -m "Release 1.0.0"  # Annotated tag (preferred)
git tag -a v1.0.0 abc123 -m "Tag old commit"  # Tag a specific commit

# Push tags
git push origin v1.0.0      # Push single tag
git push --tags             # Push all tags

# Delete tags
git tag -d v1.0.0                     # Delete local tag
git push origin --delete v1.0.0       # Delete remote tag
git push origin :refs/tags/v1.0.0     # Alternate remote delete syntax

Keep your own version of these notes — editable, searchable, and organised by your stack.

Start free