Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TortoiseGit: What's the difference between "Git Sync", "Fetch" and "Pull"?

Tags:

I am moving from TortoiseSvn to TortoiseGit. But enountered some unexpected difficulties.

My working paradigm is as simple as:

  1. Check out code
  2. Change some code
  3. Share with others for code review
  4. Commit changes

Why bother to have the 3 syntactically similar commands below?

And Pull and Fetch even share the identical icon. What a user-friendly design!

enter image description here

like image 499
smwikipedia Avatar asked Mar 14 '16 08:03

smwikipedia


People also ask

What is git sync in Tortoisegit?

The Sync Dialog provides an interface for all operations related with remote repositories in one dialog. This includes push, pull, fetch, remote update, submodule update, send patch... However, the sync dialog provides less options as the regarding dialogs (cf.

Is git fetch and pull same?

git fetch is the command that tells your local git to retrieve the latest meta-data info from the original (yet doesn't do any file transferring. It's more like just checking to see if there are any changes available). git pull on the other hand does that AND brings (copy) those changes from the remote repository.

What is fetch in Tortoisegit?

Fetch just downloads the objects and refs from a remote repository and normally updates the remote tracking branches. Pull, however, will not only download the changes, but also merges them - it is the combination of fetch and merge (cf. the section called “Merging”).

Do I need to git fetch before pull?

It's important to fetch and pull before you push. Fetching checks if there are any remote commits that you should incorporate into your local changes. If you see any, pull first to prevent any upstream merge conflicts.


2 Answers

These are three different commands:

  1. Git pull is a git fetch followed by git merge - read here
  2. Git fetch fetches info about remote repositories - read here
  3. Git sync does everything in one command meaning pull and push read here

If you want to compare git and svn workflow then git pull is like svn update. There's no direct svn version of git fetch. Git sync is like svn up && svn commit in one command

like image 139
Tomasz Madeyski Avatar answered Sep 22 '22 19:09

Tomasz Madeyski


You can do a git fetch at any time to update your remote-tracking branches under refs/remotes//.

git fetch operation never changes any of your own local branches under refs/heads, and is safe to do without changing your working copy. I have even heard of people running git fetch periodically in a cron job in the background (although I wouldn't recommend doing this).

git pull is what you would do to bring a local branch up-to-date with its remote version, while also updating your other remote-tracking branches.

like image 22
Saurabh Oza Avatar answered Sep 18 '22 19:09

Saurabh Oza