• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

GIT - Fetch Vs Pull

 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

i don't clearly understand the difference between Fetch vs Pull.

When we need to do a fetch and When we need to do a pull

I understand we need to use Pull to pull the updates or new changes or updated changes from git

Thanks
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moved to our “General Computing” forum.

Can you find a Git tutorial anywhere, or a book like this one? I think Manning are giving a 50% discount on all eBooks until late May.
 
Saloon Keeper
Posts: 15510
363
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
git pull is just a shorthand for git fetch + git merge.

With fetch, you get the changes from the remote server and synchronize your origin branch. With pull, you additionally merge the origin branch to your local branch.

Fetch is useful if you want to see what changes have been made on the remote server, without making any changes to your local copies.
 
Johnny Joseph
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Stephan, when i did git fetch - > newly added branches are updated...When i did pull it doesn't....Looks git fetch is different from git pull. Please help me in detail...
 
Stephan van Hulst
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
git pull literally performs a fetch first, so that part of the behavior is identical.

What did you do to test this? If you performed git pull immediately after a git fetch, obviously the fetch step from the pull command won't have any result, because all the work has already been done by the first time git fetch was called.
 
Johnny Joseph
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So which one is always good when i want to update a project...that's where the confusion is...

Git pull or Git fetch....Many uses Git Pull..Some uses Git Fetch...since GIT fetch updates the branches list as well....
 
Stephan van Hulst
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Like I said, fetch only updates the origin branches. An origin branch is a local representation of the branch on the remote server. You're not supposed to do any work on them. I'm not even sure to can commit or merge anything to those branches.

Like fetch, pull ALSO updates the origin branches because, as I said, it literally first performs a fetch.

The ONLY difference is that pull merges the fetched branches to the currently checked out branch, so you can continue work on the changes you fetched from the remote server.
 
Johnny Joseph
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
anywhere i can get a visual representation of pull or fetch to understand it clearly
 
Stephan van Hulst
Saloon Keeper
Posts: 15510
363
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is one, courtesy of my fantastic MS Paint skills.
git-pull.png
[Thumbnail for git-pull.png]
 
Johnny Joseph
Ranch Hand
Posts: 106
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Awesome, Stephan.....That's wonderful.....Thanks a lot...

You have a very good skill...Do you have any blog where you can have this and it would be benefitted for many ...
 
Stephan van Hulst
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I share all I know right here on CodeRanch. I don't have the patience for a blog.
 
reply
    Bookmark Topic Watch Topic
  • New Topic