git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bryan Turner <bturner@atlassian.com>
To: Erwin Villejo <erwinvillejo@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: git pull bug report
Date: Mon, 15 Nov 2021 09:56:37 -0800	[thread overview]
Message-ID: <CAGyf7-H5icSmOQ1eDx9RXDTwFcB2y9sgUxNNTF7V7Xu1MfHTEA@mail.gmail.com> (raw)
In-Reply-To: <CADL96rvRX2R_4Wm23tz88hDUztcpK531RU+Ops2UVoiOW0bCHw@mail.gmail.com>

On Mon, Nov 15, 2021 at 12:42 AM Erwin Villejo <erwinvillejo@gmail.com> wrote:
>
> > What did you do before the bug happened? (Steps to reproduce your issue)
> * make local changes, stage, and commit
> * local is ahead of upstream. confirmed by `git status`:
>
> ```
> $ git status
> On branch main
> Your branch is ahead of 'github/main' by 1 commit.
>   (use "git push" to publish your local commits)
> ```
>
> * try to pull upstream to local
>
> > What did you expect to happen? (Expected behavior)
> No-op (and NO failure) since local is ahead of upstream.
>
> > What happened instead? (Actual behavior)
> `git pull` fails with error:
>
> ```
> $ git pull
> hint: You have divergent branches and need to specify how to reconcile them.
> hint: You can do so by running one of the following commands sometime before
> hint: your next pull:
> hint:
> hint:   git config pull.rebase false  # merge (the default strategy)
> hint:   git config pull.rebase true   # rebase
> hint:   git config pull.ff only       # fast-forward only
> hint:
> hint: You can replace "git config" with "git config --global" to set a default
> hint: preference for all repositories. You can also pass --rebase, --no-rebase,
> hint: or --ff-only on the command line to override the configured default per
> hint: invocation.
> fatal: Need to specify how to reconcile divergent branches.
> ```
>
> > What's different between what you expected and what actually happened?
> I expected no failure and no-op since local is ahead of upstream.
> Instead, `git pull`
> fails because it thinks the branches have diverged.

You're making a logical, but still incorrect, assumption about what
the "git status" output means. "git status" does NOT actually check
the remote server.

When you pull, there are typically 3 refs that are involved, not 2.
(Given it appears you're on "main", I'll use that name below.)
refs/heads/main: This is the local branch you're working on
refs/remotes/github/main: This is your _local copy_ of what the
_remote_ branch was pointed at the last time you fetched or pulled
successfully
refs/heads/main on Github: This is the remote branch you're trying to push to

When you run "git status", it is NOT talking to Github; it's simply
comparing the state of your "refs/heads/main" and
"refs/remotes/github/main" branches.

When you run "git pull", it's actually talking to Github, which allows
it to find out about commits that are present remotely but have not
been fetched to your "refs/heads/main" or "refs/remotes/github/main"
branches.

If you run "git fetch", rather than "git pull", that will update your
local "refs/remotes/github/main" branch without trying to also update
"refs/heads/main". If you then run "git status", it will tell you your
"main" branch has diverged, just like "git pull" does, instead of
showing it as ahead.

Hope this helps,
Bryan

>
> > Anything else you want to add:
> I found this bug in VSCode. VSCode runs `git pull` first before `git
> push` when pushing to upstream.
> This bug causes pushing via VSCode to always fail, although it can be
> worked around by simply opening
> a terminal and running `git push` manually.
>
> [System Info]
> git version:
> git version 2.33.1
> cpu: x86_64
> no commit associated with this build
> sizeof-long: 8
> sizeof-size_t: 8
> shell-path: /bin/sh
> uname: Linux 5.15.2-arch1-1 #1 SMP PREEMPT Fri, 12 Nov 2021 19:22:10
> +0000 x86_64
> compiler info: gnuc: 11.1
> libc info: glibc: 2.33
> $SHELL (typically, interactive shell): /bin/bash
>
>
> [Enabled Hooks]
>
> Best regards,
> Erwin

  parent reply	other threads:[~2021-11-16  1:24 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-15  8:42 git pull bug report Erwin Villejo
2021-11-15  8:54 ` Bagas Sanjaya
2021-11-15  8:56   ` Erwin Villejo
2021-11-15  9:12     ` Bagas Sanjaya
2021-11-15  9:19       ` Erwin Villejo
2021-11-15  9:39         ` Erwin Villejo
2021-11-15 18:15           ` Bryan Turner
2021-11-15 18:22             ` Erwin Villejo
2021-11-15 17:56 ` Bryan Turner [this message]
2021-11-15 20:40 ` Junio C Hamano
     [not found]   ` <CADL96rsnUCXchnrTa1rZ7WgJz2kDA-3TzeOiCy4AXNFdXtTmng@mail.gmail.com>
2021-11-16  1:43     ` Erwin Villejo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAGyf7-H5icSmOQ1eDx9RXDTwFcB2y9sgUxNNTF7V7Xu1MfHTEA@mail.gmail.com \
    --to=bturner@atlassian.com \
    --cc=erwinvillejo@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).