git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: How to update a cloned git repository

From
Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Date
Sep 11, 2012, 11:06 UTC
Message-ID
<vpq7gs0es4f.fsf@bauges.imag.fr>
In-Reply-To
<k2n4v2$88t$1@ger.gmane.org>
"Joachim Schmitz" <jojo@schmitz-digital.de> writes:
Show 8 quoted lines
> Hi folks
>
> Probably a beginner's question...
>
> If I did a
>    git clone git://guthub.com/git/git.git
> and worked on some own branches of pu
>    git checkout pu;git checkout -p mybranch;
I guess you meant "git checkout -b mybranch" (not -p).
Show 6 quoted lines
> hack;hack;...;git commit -a -s
>
> how to update my repository once the the one on github changed? A
> plain git pull or git fetch;git merge keeps failing on my with lots of
> conflicts, none of which relate to any of the changes I did (and hence
> wouldn't know how to resolve)

Short answer: don't work on pu. Work on master unless you have a good reason not to.

Longer answer: the pu branch in git.git is often re-written, hence the commit on which you started hacking once existed in git.git's pu, but it probably no longer is.

You cloned this:
--A---B---C <-- origin/pu
Hacked to this
         origin/pu
          |
          v
--A---B---C---D---E <-- mybranch
and the next fetch resulted in something like this:
    B'---C'---D'---F <-- origin/pu
   /
--A---B---C---D---E <-- mybranch

while you could have expected that if origin/pu had just been fast-forwarded with a new commit F:

            F <-- origin/pu
           /
--A---B---C---D---E <-- mybranch

As a result, "git merge" computes a common ancestor very far backward in history. Instead of merging only your changes with new pu content, it merges the old history of pu (plus your changes) with the new history of pu, and you get spurious conflicts.

The solution is to rebase your changes (and only yours). My advice is to rebase them on master, like this (replace 42 by the number of commits you want to rebase in HEAD~42):

  git rebase HEAD~42 --onto origin/master

Once you did this, you can start using "git pull" (or "git pull --rebase") as usual.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Previous: Joachim SchmitzNext: Joachim Schmitz
Message 2 of 14 in “How to update a cloned git repository”
  1. Joachim SchmitzSep 11, 2012
  2. Matthieu MoySep 11, 2012
  3. Joachim SchmitzSep 11, 2012
  4. Matthieu MoySep 11, 2012
  5. Sitaram ChamartySep 11, 2012
  6. Junio C HamanoSep 11, 2012
  7. Joachim SchmitzSep 11, 2012
  8. Matthieu MoySep 11, 2012
  9. Joachim SchmitzSep 11, 2012
  10. Erik Faye-LundSep 11, 2012
  11. Junio C HamanoSep 11, 2012
  12. Matthieu MoySep 11, 2012
  13. Joachim SchmitzSep 11, 2012
  14. Matthieu MoySep 12, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.