What are the differences between ‘git pull’ and ‘git fetch’?

Git-Logo

What are the differences between git pull and git fetch?

Answer:

In the simplest terms, git pull does a git fetch followed by a git merge.

You can do a git fetch at any time to update your remote-tracking branches under refs/remotes/<remote>/. This 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).

A 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.

Git documentation: git pull

Source:
http://stackoverflow.com/a/292359/1794834

When do you use git rebase instead of git merge?

Git-Logo

When is it recommended to use git rebase vs. git merge?
Do I still need to merge after a successful rebase?

Answer:
Short Version

  • Merge takes all the changes in one branch and merge them into another branch in one commit.
  • Rebase says I want the point at which I branched to move to a new starting point

So when do you use either one?

Merge

Let’s say you have created a branch for the purpose of developing a single feature. When you want to bring those changes back to master, you probably want merge (you don’t care about maintaining all of the interim commits).

Rebase
A second scenario would be if you started doing some development and then another developer made an unrelated change. You probably want to pull and then rebase to base your changes from the current version from the repo.

Source:
http://stackoverflow.com/a/804156/1794834

Pin It on Pinterest