The difference between git pull, git fetch and git clone (and git rebase)

Mike Pearce

Update: So, over a year later and I’ve had some feedback from a colleague (thanks Ben!). Nothing here is drastically wrong, but some clarifications should help!

When I started out with git …

… who am I kidding, I’m still a git n00b. Today, I tweeted about git. I wanted to know what the differene between pull, fetch and clone is. After discovering that, really, 140 characters isn’t enough to answer the questions, I had a play around.

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.

The above will merge the remote…

View original post 354 剩余字数

关于 git 合并不在本地的branch

团队开始使用git作为代码控制工具,大家在一个master上面提交,我为了开发不受到别人影响,首先自己建立了一个分支locationAlbum, 使用git branch命令查看:

master
* locationAlbum

后来团队其他人发现了版本控制混乱问题,决定用git-flow这个工具解决问题。他们首先用git-flow在master上面建立了一个develop分支,大家在develop上面开发。当我准备合并时,发现git branch看不到他们建立的分支:

>git branch

master

*locationAlbum

 

但是使用git ls-remote命令可以查看的到

179b789fb3e5562a1d5e1a221252b3cfeb8afb29 HEAD
dadf5a5d829a7a11d6f9a594f8262eb1b5931acc refs/heads/develop
deef2cd04eb8c7c8d72d107917e551e53665424e refs/heads/locationAlbum
179b789fb3e5562a1d5e1a221252b3cfeb8afb29 refs/heads/master

我强制使用fetch命令,下载develop,发现不奏效。

fatal: ‘develop’ does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

我将上面内容paste到google中,搜索到需要保证我可见的分支名在.git/refs/heads 中,大概知道怎么回事了,尝试的修改了.git/refs/heads 的引用添加了develop,再用git branch查看,果然出现了!

develop
* locationAlbum
master

git checkout locationAlbum也没有问题。此后merge两个版本,重新提交,合并代码解决了问题。