Alexander Mills
Alexander Mills

Reputation: 100486

git status without checking out a branch

Say I have:

git fetch origin
git status "remotes/origin/master"

I am not sure if I can check the status of a branch that I haven't checked out, so let's say I checkout a branch like so:

git branch foo "remotes/origin/master"
git checkout foo
git status

my question is 2-fold:

  1. Can I get the git status of a branch without checking it out?
  2. Would the git status of foo ever be "unclean"? I would assume the git status of foo would always be "clean" and "up-to-date with the remote".

Upvotes: 4

Views: 1445

Answers (1)

John Zwinck
John Zwinck

Reputation: 249642

Can I get the git status of a branch without checking it out?

No, because git status shows the status of the working tree. If you haven't checked out a branch, there is no working tree for it.

Would the git status of foo ever be "unclean"?

It could be, if you have files which are not checked in (and not in .gitignore). Those files would survive git checkout <branch>, and would appear as new files in any branch.

Upvotes: 6

Related Questions