DEV Community

Cover image for Day (10/30) - git branch -a + git remote show origin – Inspecting remote branches
Ruqaiya Beguwala
Ruqaiya Beguwala

Posted on • Originally published at Medium

Day (10/30) - git branch -a + git remote show origin – Inspecting remote branches

When working with Git, keeping track of both local and remote branches is crucial for efficient collaboration. Two powerful commands git branch -a and git remote show origin help developers inspect remote branches, understand repository structure, and avoid conflicts.

1. What is git branch -a?

The git branch -a command lists all branches (both local and remote) in your Git repository.

Example:

$ git branch -a
* main
  dev
  feature/login
  remotes/origin/main
  remotes/origin/dev
  remotes/origin/feature/dashboard

Enter fullscreen mode Exit fullscreen mode
  • * indicates the currently checked-out branch (main).
  • Local branches: maindevfeature/login.
  • Remote branches (prefixed with remotes/origin/).

When to Use git branch -a?

✅ Quickly check all available branches.
✅ Compare local vs. remote branches.
✅ Identify branches that may need fetching.


2. What is git remote show origin?

This command provides detailed information about the remote repository (origin), including:

  • Remote branch tracking status
  • Branches that are ahead or behind
  • Branches available for fetch/push

Example:

$ git remote show origin
* remote origin
  Fetch URL: https://github.com/user/repo.git
  Push URL: https://github.com/user/repo.git
  HEAD branch: main
  Remote branches:
    main tracked
    dev tracked
    feature/dashboard new (next fetch will store in remotes/origin)
  Local branches configured for 'git pull':
    main merges with remote main
    dev merges with remote dev
  Local refs configured for 'git push':
    main pushes to main (up to date)
    dev pushes to dev (local out of date)
Enter fullscreen mode Exit fullscreen mode

Key Insights from git remote show origin

🔹 Tracked branches (maindev) are synced with remote.
🔹 "new" branches (like feature/dashboard) exist remotely but aren't fetched yet.
🔹 "local out of date" means dev needs a git pull.

When to Use git remote show origin?

✅ Debugging sync issues between local and remote.
✅ Checking if a branch exists upstream.
✅ Verifying push/pull configurations.


3. Key Differences: git branch -a vs. git remote show origin

Feature git branch -a git remote show origin
Scope Lists all branches (local + remote) Shows detailed remote tracking info
Tracking Status ❌ No ✅ Yes (ahead/behind)
Fetch/Push Info ❌ No ✅ Yes
New Branches Shows only fetched remotes Highlights "new" remote branches

4. Practical Use Cases

Use Case 1: Syncing a New Remote Branch

If a teammate creates feature/payment remotely:

$ git branch -a
# Doesn't show feature/payment yet

$ git remote show origin
# Shows "feature/payment new (next fetch will store)"

$ git fetch
$ git branch -a
# Now shows remotes/origin/feature/payment
Enter fullscreen mode Exit fullscreen mode

Use Case 2: Checking Branch Synchronization

Before pushing changes:

$ git remote show origin
# "dev pushes to dev (local out of date)" → Need to pull first!
Enter fullscreen mode Exit fullscreen mode

Use Case 3: Cleaning Up Obsolete Branches

$ git remote prune origin  # Deletes stale remote-tracking branches
$ git branch -a  # Verifies cleanup
Enter fullscreen mode Exit fullscreen mode

5. Pro Tips & Best Practices

🔹 Always Fetch Before Checking Branches

git fetch --all  # Updates all remote references
git branch -a    # Now shows latest branches
Enter fullscreen mode Exit fullscreen mode

🔹 Use -vv for More Branch Details

git branch -vv   # Shows tracking branch & commit difference

Enter fullscreen mode Exit fullscreen mode

🔹 Prune Stale Branches Regularly

git remote prune origin  # Cleans up deleted remote branches
Enter fullscreen mode Exit fullscreen mode

🔹 Set Upstream Tracking for Easier Push/Pull

git push -u origin feature/login  # Sets tracking automatically
Enter fullscreen mode Exit fullscreen mode

6. Conclusion

git branch -a and git remote show origin are essential for inspecting remote branches, debugging sync issues, and maintaining a clean repository.

  • Use git branch -a for a quick branch overview.
  • Use git remote show origin for detailed tracking status.
  • Fetch regularly to keep branch lists updated.

Up next: git fetch --prune – Clean up stale remote-tracking branches


Daily advance GIT tips in your inbox—worth starting? Respond to my poll here🚀
For more useful and innovative tips and tricks, Let's connect on Medium

Top comments (6)

Collapse
 
charles_koffler_bcabc582b profile image
Charles Koffler

Thank you for giving me clues to me for better understand branch interests and handling in Git, and those two commands. Cheers

Collapse
 
ruqaiya_beguwala profile image
Ruqaiya Beguwala

Glad that you like it. You can checkout my other posts as well. Hope you find something useful. Cheers!

Collapse
 
charles_koffler_bcabc582b profile image
Charles Koffler • Edited

I often wonder why do we need so many commands in git. Your explanations are well presented and written, and great to give use cases and tips

Thread Thread
 
ruqaiya_beguwala profile image
Ruqaiya Beguwala

Thank you so much for your kind words. It literally made my day!

Thread Thread
 
charles_koffler_bcabc582b profile image
Charles Koffler

Oh thank you so much. Have a fantastic day. You know I've finally understood the value of local and distant branches thanks to you

Thread Thread
 
ruqaiya_beguwala profile image
Ruqaiya Beguwala

Thank you!