To get to know how far ahead and/or behind a branch is compared to its remote, there's the git status
command.
But git status
only shows the status of the current branch.
Looks like to get to know the status of the other branches in the same directory, I need to switch to each branch and run git status
again.
However, switching branches is not always possible, as the current branch may not be clean.
Is there any way to get to know the status of the other branches without switching to the other branches?
To directly answer the question that you posed in the title: you can't run git status
in other branches. git status
shows you two key pieces of information: how you have changed the index (how you have staged changes) that are different from the most recent commit on your branch, and how you have changed the working directory and made changes that you haven't staged.
In other words, status
shows you a combined diff of the HEAD to the index with a diff of the index to the working directory. So it only makes sense to get the equivalent of git status
on the current branch, since it takes the index and working directory into account.
With that caveat out of the way, it sounds like you're only interested in ahead/behind count, and you want the ahead/behind count for some other branch compared to its upstream.
Even though ahead/behind count is one of the things git status
shows as somewhat ancillary information, it is the easiest way to find the ahead/behind count for the current branch, as you noted.
To show ahead/behind for all branches, you can use the helpful script in this answer.