-3

Today I experienced, that

git status

is not sufficient to establish, that there are no changes in ones working directory, which aren't also stored in the (remote) repository. So, how can this be established?

PS.

git status

said

On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

Then I switched to another branch using

git checkout branchName

which contained local commits -- I was not even aware that this is possible.

  • 1
    What does git status and git fetch origin say? – Christoph Jan 25 '19 at 16:01
  • _"is not sufficient to establish, that there are no changes in ones working directory"_ - yes it is. _"which aren't also stored in the (remote) repository"_ - changes aren't stored in the remote, but commits are. – evolutionxbox Jan 25 '19 at 16:24
  • @evolutionxbox -- I've to use "git push" in order to get commits into the remote. So your statement is wrong. –  Jan 25 '19 at 16:28
  • I think you commented on the wrong question. `git fetch` is to _fetch_ commits from the remote, but `git status` still won't show the _changes_ only how many commits the local branch is "ahead" or "behind". – evolutionxbox Jan 25 '19 at 16:31

1 Answers1

2

It sounds like you may have misunderstood the response from git status and what it means to have a "local working directory" in git.

For basically every use case, each git command you run will only operate on the current local branch. If you have multiple local branches on your machine, usual git commands won't traverse them; your work is compartmentalized.

$ git checkout master
$ git status
nothing to commit, working tree clean
$ git checkout myBranch
$ git status
local 'myBranch' is ahead of 'remote/myBranch' by 3 commits
$ git checkout myOtherBranch
$ git status
local 'myOtherBranch' is behind 'remote/myOtherBranch' by 2 commits

You are changing contexts when you change branches (as you should be). There is git voodoo that you can invoke to see all branch statuses at once. See this answer.

Ian MacDonald
  • 13,472
  • 2
  • 30
  • 51
  • Please answer the question asked. I established by myself that my understanding is not correct! –  Jan 25 '19 at 16:09
  • 1
    The answer that I linked is short-and-sweet. It provides a script that can be copy-pasted into a file on your system. The second block in the answer shows an invocation of the script and the output you should expect. – Ian MacDonald Jan 25 '19 at 16:15
  • The script linked iterates over the local branches and reports back how far ahead and/or behind the remote branch they are. The reason that I linked the answer is because the script already exists and you do not have to write it yourself. I do not think the snark in your comments was warranted. – Ian MacDonald Jan 25 '19 at 16:21