How to track remote branch in Git

Branch tracking in Git creates a link between your local branch and a remote branch, enabling simple push/pull operations without specifying the remote each time. As the creator of CoreUI with 26 years of development experience, I’ve configured branch tracking across hundreds of repositories to streamline team collaboration and automate deployment workflows.

The fastest way is using git branch --set-upstream-to or the -u flag when pushing.

Track When Pushing

# Push and set tracking in one command
git push -u origin feature-branch

# Now you can use simple commands:
git push  # Pushes to origin/feature-branch
git pull  # Pulls from origin/feature-branch

Set Tracking for Existing Branch

# Set tracking for current branch
git branch --set-upstream-to=origin/main

# Or shorter form
git branch -u origin/main

# Set tracking for specific branch
git branch -u origin/develop develop

Check Tracking Status

# View tracking branches
git branch -vv

# Output shows tracking info:
# * main    abc1234 [origin/main] Latest commit
#   feature def5678 [origin/feature: ahead 2] New feature

Track Remote Branch on Clone

# Clone automatically tracks default branch
git clone https://github.com/username/repo.git

# Check tracking
cd repo
git branch -vv
# * main abc1234 [origin/main] Initial commit

Checkout and Track Remote Branch

# List remote branches
git branch -r
# origin/main
# origin/develop
# origin/feature-x

# Checkout and track in one command
git checkout --track origin/feature-x

# Or shorter form (Git auto-detects)
git checkout feature-x

# Git automatically creates local branch tracking origin/feature-x

Track Different Remote Branch Name

# Local branch: my-feature
# Remote branch: origin/team-feature

git checkout -b my-feature
git branch -u origin/team-feature

# Now my-feature tracks origin/team-feature
git push  # Pushes to origin/team-feature
git pull  # Pulls from origin/team-feature

Stop Tracking Remote Branch

# Remove tracking relationship
git branch --unset-upstream

# Branch still exists but no longer tracks remote
git branch -vv
# * feature abc1234 New feature (no tracking info)

Track Multiple Remotes

# Add multiple remotes
git remote add upstream https://github.com/original/repo.git
git remote add fork https://github.com/yourname/repo.git

# Track different remotes for different branches
git checkout main
git branch -u upstream/main

git checkout develop
git branch -u fork/develop

# Verify
git branch -vv
# * develop abc1234 [fork/develop] Latest dev
#   main    def5678 [upstream/main] Latest main

Push to Tracked Branch

# With tracking configured
git push

# Without tracking, you need:
git push origin feature-branch

# Force push to tracked branch
git push --force

# Or safer force push
git push --force-with-lease

Pull from Tracked Branch

# With tracking configured
git pull

# Equivalent to:
git fetch origin
git merge origin/feature-branch

# Use rebase instead
git pull --rebase

Auto-Track on Push (Global Config)

# Configure Git to auto-track on first push
git config --global push.autoSetupRemote true

# Now first push automatically sets up tracking
git checkout -b new-feature
git push  # Automatically pushes to origin/new-feature and sets tracking

View Tracking Configuration

# Check specific branch tracking
git config branch.main.remote
# origin

git config branch.main.merge
# refs/heads/main

# View all branch configs
git config --get-regexp branch
# branch.main.remote origin
# branch.main.merge refs/heads/main

Fix Tracking After Rename

# Rename local branch
git branch -m old-name new-name

# Update tracking (old tracking is lost)
git branch -u origin/new-name

# Or push and set tracking
git push -u origin new-name

Track Branch in Different Repository

# Add remote for different repo
git remote add other https://github.com/other/repo.git

# Fetch branches
git fetch other

# Create local branch tracking other repo
git checkout -b other-feature
git branch -u other/feature

# Now local other-feature tracks other/feature

Best Practice Note

This is how we configure branch tracking in all CoreUI repositories for efficient Git workflows. Branch tracking simplifies push/pull operations and makes collaboration smoother by establishing clear relationships between local and remote branches. Always set up tracking when creating feature branches, use git push -u on first push, and enable push.autoSetupRemote globally for automatic tracking configuration.

For related Git operations, check out how to push specific branch in Git and how to fetch specific branch in Git.


Speed up your responsive apps and websites with fully-featured, ready-to-use open-source admin panel templates—free to use and built for efficiency.


About the Author