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

Re: Pull and fetch

From
Sean <seanlkml@sympatico.ca>
Date
Nov 23, 2006, 20:36 UTC
Message-ID
<BAYC1-PASMTP11EB389CA59410315B2F8AAEE20@CEZ.ICE>
In-Reply-To
<20061123203950.5d47421f@paolo-desktop>

On Thu, 23 Nov 2006 20:39:50 +0100 Paolo Ciarrocchi <paolo.ciarrocchi@gmail.com> wrote:

Show 5 quoted lines
> OK, make sense. So let's try with an experiment:
> paolo@paolo-desktop:~$ mkdir test
> paolo@paolo-desktop:~$ cd test
> paolo@paolo-desktop:~/test$ git-init-db 
> defaulting to local storage area

At this point your "master" branch will be empty. You can see this by doing a "git log"

> paolo@paolo-desktop:~/test$ git fetch ../git master:testbranch
> warning: no common commits
> remote: Generating pack...

If you do "git log" at this point you'll see your master branch is still empty. All you've done is fetched the remote branch into your new repo as "testbranch"

> [skip]
> paolo@paolo-desktop:~/test$ git pull ../git master:testbranchpull
> * refs/heads/testbranchpull: storing branch 'master' of ../git
>   commit: e945f95

This command is different than fetch. After fetching the remote branch into your repo as "testbranchpull", it then merges it with your currently checked out branch (master). At this point if you do a "git log" you'll see your master is now populated with the results of the merge (well in this case a fast forward).

So this nicely shows the difference of fetch and pull, and explains how your "master" branch came to have something in it.

 
Show 9 quoted lines
> Now I have 3 branches:
> paolo@paolo-desktop:~/test$ git branch
> * master
>   testbranch
>   testbranchpull
> 
> All the branches have the same content, I expect to see differences between testbranch 
> and testbranchpull. The first one is the end result of a fetch, the second one is
> the end result of a pull.

Yes, they will all have the same content. As your local repo diverges from the remote (as you make local commits) the difference between fetch and pull will become more obvious and pronounced.

> git status always says:
>   nothing to commit
> 
> Why?

This just means you have no uncommitted local changes in your repo. Edit one of the file, and before committing the change, do "git status" again and it will list the file as modified.

> What will happen if I repeat the same commands:
>   git fetch ../git master:testbranch
>   git pull ../git master:testbranchpull
> after a change in the git master branch?
Try it out :o)

Afterward, both testbranch and testbranchpull will be direct copies of the other repo's master. The fetch command will do nothing to "master". However, after updating your testbranchpull, the pull command will merge (or fast forward) its contents into "master".

Cheers,
Previous: Paolo CiarrocchiNext: J. Bruce Fields
Message 2 of 6 in “Pull and fetch”
  1. Paolo CiarrocchiNov 23, 2006
  2. SeanNov 23, 2006
  3. J. Bruce FieldsNov 24, 2006
  4. Documentation: clarify tutorial pull/merge discussionJ. Bruce Fields, Nov 26, 2006
  5. Paolo CiarrocchiNov 26, 2006
  6. Paolo CiarrocchiNov 24, 2006

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.