I've been reading about git pull
and git fetch
, I'm getting a little confused now. So on the master branch, there have been commits made since I've last done work. If I want to update my local repository to continue working, am I supposed to pull the commits from the master branch to my own branch? I tried to do a git fetch
from my own branch to update it. But from what I read, this doesn't completely update my local repository and that I would need to merge.

- 313
- 2
- 23
-
"master branches"? there's only one branch called master.. – ItayB Feb 06 '17 at 20:21
-
@ItayB: Well, there's (zero or) one `master` *per repository*. If you have a Git repository yourself, and you `git fetch` from another Git repository named `origin`, there are two `master`s: yours, and origin's. But it really does depend on what/how you count! – torek Feb 06 '17 at 20:43
-
@torek agree - it depend how you count. I'm counting `master` and `origin/master` as different branches – ItayB Feb 06 '17 at 20:56
3 Answers
git fetch
only downloads patch files from a remote repository, but does not apply them. In simple terms git pull
is a short-hand for git fetch; git merge;
.
To update your files git fetch
is not sufficient - make a git pull
Also, the question is already answered here: https://stackoverflow.com/questions/292357/difference-between-git-pull-and-git-fetch

- 1
- 1

- 183
- 1
- 10
-
Okay, that makes sense, thank you. To update my local repository, do I checkout the master branch and perform a `git pull origin master` or do this on my own branch? – Jasmine Feb 06 '17 at 20:25
-
@Jasmine: for beginners, I strongly recommend avoiding `git pull`, as it seems to be overly magic. Use `git fetch`, which directs your Git to call up the other Git at `origin` and download items, and then use `git merge` or `git rebase`—whichever your work-flow calls for—to *integrate* the items you just picked up. When something goes wrong (and eventually it will), you'll know which *part* went wrong and hence at least know what to ask next. It's also useful to know that `git fetch` is always safe no matter what state you are in, but `git merge` and `git rebase` need things to be "clean". – torek Feb 06 '17 at 20:49
git pull
is actually a combination of: git fetch
& git merge
. You probably what to do the following:
git checkout master
# switch to master branch on your local repo.git status
# make sure you are cleangit pull
# get last commits from remote repogit checkout <your-branch>
# switch back to your side branchgit merge master
# merge the master commits into your-branch- optionally:
git push origin <your-branch>
# to backup your commits/updates in remote repo

- 10,377
- 9
- 50
- 77
git fetch
will download all the repository information from your remote
. This stores it in the remote (try running git remote show
). So now you will have a branch called origin\master
. You can see your branches on your remote by running git branch -a
origin\master
is different from master
so you will need to git merge origin\master
to syncronize with your remote origin.
git pull
automatically runs several commands
git fetch
git merge origin\master
I would recommend going through this quick tutorial: https://try.github.io/

- 1,380
- 2
- 19
- 47