-3

When I do a git st in a repository I get the message:

Your branch is up to date with 'origin/main'.

But then when I do a git pull a lot of commits are downloaded.

But I thought the current checkout/working directory is up-to-date with origin?

Do I understand something wrong here?

Alex
  • 41,580
  • 88
  • 260
  • 469
  • 1
    `git st` is not a git(1) command. Did you mean `git status`? – Guildenstern May 11 '23 at 06:18
  • 1
    If you're unsure: `git config --list | grep alias.st` – YSC May 11 '23 at 07:20
  • Does this answer your question? [Why does git status show branch is up-to-date when changes exist upstream?](https://stackoverflow.com/questions/27828404/why-does-git-status-show-branch-is-up-to-date-when-changes-exist-upstream) – jonrsharpe May 11 '23 at 07:47

3 Answers3

3

git status displays the working tree status, i.e.

what you would commit by running git commit [...] and what you could commit by running git add before running git commit

It has nothing to do with any remote status.

See docs.

This SO post and this one discuss checking for remote changes.

buddemat
  • 4,552
  • 14
  • 29
  • 49
  • 1
    Thanks for that. As for the docs, these contain names like `working tree`, `index file`, `HEAD`, `tracked`. Is there some documentation available in some simple English? – Alex May 11 '23 at 05:50
  • There are some resources that attempt to explain this without diving in deep. This [simple guide](https://rogerdudler.github.io/git-guide/) tries to explain the concepts you asked about in a few sentences. However, it is worth spending a bit of time getting a bit deeper into the general concept. One important aspect is that `git` is a _distributed_ version control system, that does not need any remote repository at all. – buddemat May 11 '23 at 06:05
  • 1
    @Alex https://www.git-scm.com/docs/gitglossary could help. – ElpieKay May 11 '23 at 06:48
2

origin/main is what git calls a "tracking branch". This is a local copy of a branch in another repository (called a remote). The key here is that this local copy is only updated with commands like git fetch or git pull. When you run git status, it compares your local branch main with the tracking branch origin/main. It does NOT query the remote to find out what its main branch is like.

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
2

git status does not reach out to the remote repository to see what is there. It only looks at what is already cached locally in refs/remotes/origin/main a.k.a. origin/main.

To see whether the repository is up to date with the remote, the tools to use are git fetch and git pull.

j6t
  • 9,150
  • 1
  • 15
  • 35
  • I have no idea what `refs/remotes/...` mean – Alex May 11 '23 at 05:53
  • When we talk about the (local) branch `main`, then we talk about a "ref" whose full name is actually `refs/heads/main`. All (local) branches live under the `refs/heads` hierarchy. All remote-tracking branches live under the hierarchy `refs/remotes`. These are managed by `git fetch` (and `git pull`). There is usually a remote repository called `origin`, therefore, its remote tracking branches are in the hierarchy `refs/remotes/origin`, for example `refs/remotes/origin/main`, which can be referred to in abbreviated form with `origin/main`. – j6t May 11 '23 at 06:00