Remote Branches
Branching in a distributed environment means you have both Local Branches and Remote Tracking Branches.
1. Inspecting Remote Branches
You can see the branches that exist on your remotes without checking them out:
# List all remote branches
git branch -r
# List all branches (Local + Remote)
git branch -a
# See verbose info (Which local branch tracks which remote)
git branch -vv2. Tracking a Remote Branch
When you want to work on a branch that someone else pushed to GitHub:
# Create a local branch that 'tracks' the remote one
git checkout --track origin/feature-api
# Shorthand for simple cases
git checkout feature-apiOnce tracking is set up, git pull and git push will automatically know which remote branch to communicate with.
3. Pruning Stale Branches
A common headache in long-lived projects is "branch clutter"—remotes having deleted branches that still show up in your local list.
# Remove local references to remote branches that no longer exist
git fetch --prune4. Deleting Remote Branches
Finished with a feature? Don't just delete it locally; remove it from the cloud too:
# Delete the 'feature-old' branch on the remote 'origin'
git push origin --delete feature-old[!IMPORTANT] Remote Tracking Branches are Read-Only You cannot
checkoutdirectly to a remote branch likeorigin/main. You must create a local branch that follows it. Think of the remote branch as a "bookmark" that updates whenever youfetch.