Skip to content



Difference between git pull, git fetch and git clone (and git rebase)



04 January 2017no comments Random Posts

333 Total Views

Git Pull

From what I understand, git pull will pull down from a remote whatever you ask (so, whatever trunk you’re asking for) and instantly merge it into the branch you’re in when you make the request. Pull is a high-level request that runs ‘fetch’ then a ‘merge’ by default, or a rebase with ‘–rebase’. You could do without it, it’s just a convenience.

1
2
3
4
5
%> git checkout localBranch
%> git pull origin master
%> git branch
master
* localBranch

The above will merge the remote “master” branch into the local “localBranch”.

Git fetch

Fetch is similar to pull, except it won’t do any merging.

1
2
3
4
5
6
%> git checkout localBranch
 %> git fetch origin remoteBranch
%> git branch
master
* localBranch
remoteBranch

So, the fetch will have pulled down the remoteBranch and put it into a local branch called “remoteBranch”. creates a local copy of a remote branch which you shouldn’t manipulate directly; instead create a proper local branch and work on that. ‘git checkout’ has a confusing feature though. If you ‘checkout’ a local copy of a remote branch, it creates a local copy and sets up a merge to it by default.

Git clone

Git clone will clone a repo int a newly created directory. It’s useful for when you’re setting up your local doodah

1
2
3
4
5
%> cd newfolder
%> git clone git@github.com:whatever/something.git
%> git branch
 * master
remoteBranch

Git clone additionally creates a remote called ‘origin’ for the repo cloned from, sets up a local branch based on the remote’s active branch (generally master), and creates remote-tracking branches for all the branches in the repo

Git rebase

Finally, git rebase is pretty cool. Anything you’ve changed by committing to your current branch but are no in the upstream are saved to a temporary area, so your branch is the same as it was before you started your changes, IE, clean. It then grabs the latest version of the branch from the remote If you do ‘git pull –rebase’, git will pull down the remote changes, rewind your local branch, then replays all your changes over the top of your current branch one by one, until you’re all up to date.

Spread The Love, Share Our Article

  • Delicious
  • Digg
  • Newsvine
  • RSS
  • StumbleUpon
  • Technorati
  • Twitter

Related Posts

There are no related posts on this entry.

Facebook Iconfacebook like buttonTwitter Icontwitter follow buttonFollow Us
Follow

Get every new post delivered to your Inbox

Join other followers