git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Rast <trast@student.ethz.ch>
To: Hilco Wijbenga <hilco.wijbenga@gmail.com>
Cc: Git Users <git@vger.kernel.org>
Subject: Re: Your branch and 'origin/master' have diverged
Date: Tue, 14 Aug 2012 10:27:58 +0200	[thread overview]
Message-ID: <87zk5x6fox.fsf@thomas.inf.ethz.ch> (raw)
In-Reply-To: <CAE1pOi1WTbMSK8dOus6pFCa2C9vGA8QNE3+8w0LFmGkvcfq5fg@mail.gmail.com> (Hilco Wijbenga's message of "Mon, 13 Aug 2012 12:58:40 -0700")

Hilco Wijbenga <hilco.wijbenga@gmail.com> writes:

> # On branch master
> # Your branch and 'origin/master' have diverged,
> # and have 250 and 19 different commit(s) each, respectively.
> #
> nothing to commit (working directory clean)
>
> He asked me what to do and I told him to do what has always worked for
> me in the past when something like this happened: gitk, "reset master
> branch to here" (to a commit before the divergence and using --hard),
> git pull origin master. Problem solved.

There are several layers of pitfalls and misunderstandings here.

* Is your work origin/master..master (that is, anything in master but
  not origin/master) really so worthless as to make "scrap it all!" the
  normal course of resolution?

  Or perhaps the real reason for the divergence is that upstream rewrote
  its master (eeeek!), in which case you should get them acquainted with
  the clue bat... and probably rebase instead of merge.

* pull = fetch + merge!  Repeat this a few times until it sinks in.
  Then print it on A0 and stick it up in your office or something.

  For your case this means that the pull command is roughly equivalent
  to

    git fetch origin master
    git merge FETCH_HEAD

  The two-arg form of fetch does *not* update origin/master.  Assuming
  you got the reset right, the merge will fast-forward to whatever
  origin's master points to -- but origin/master is still the old state!

* Resetting to something that you think will fast-forward, only to then
  fast-forward it to the newest state, is silly.  You can just reset to
  the newest state instead.

Taking all of this together, I think you should stop using two-arg
pull[*] or fetch, and replace your error-prone recipe with simply

  git fetch
  git reset --hard origin/master

Assuming, as before, that your local work is worthless.  Is it?
Otherwise it would be better to run something like

  git fetch
  git rebase origin/master


[*] it's ok if you use it with an URL instead of a remote nickname

-- 
Thomas Rast
trast@{inf,student}.ethz.ch

  reply	other threads:[~2012-08-14  8:28 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-13 19:58 Your branch and 'origin/master' have diverged Hilco Wijbenga
2012-08-14  8:27 ` Thomas Rast [this message]
2012-08-14 17:04   ` Hilco Wijbenga
2012-08-14 17:19     ` Junio C Hamano
2012-08-14 18:32       ` Hilco Wijbenga
2012-08-14 18:49         ` Junio C Hamano
2012-08-14 20:12         ` Thomas Rast
2012-08-14 20:49           ` Junio C Hamano
2012-08-15  6:59             ` Thomas Rast
2012-08-15 17:30               ` Junio C Hamano
2012-08-15 18:38                 ` Holger Hellmuth (IKS)
2012-08-15 19:07                   ` Junio C Hamano
2012-08-15 19:22                 ` Junio C Hamano
2012-08-16 16:24                   ` Jeff King
2012-08-16 17:57                     ` Junio C Hamano
2012-08-16 16:21               ` Jeff King
2012-08-14 22:15           ` Hilco Wijbenga
2012-08-14 22:35             ` Junio C Hamano
2012-08-14 16:02 ` PJ Weisberg
2012-08-14 17:07   ` Hilco Wijbenga

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=87zk5x6fox.fsf@thomas.inf.ethz.ch \
    --to=trast@student.ethz.ch \
    --cc=git@vger.kernel.org \
    --cc=hilco.wijbenga@gmail.com \
    /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).