Jasmine
Jasmine

Reputation: 323

Updating local git repository with remote repository

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.

Upvotes: 2

Views: 6199

Answers (3)

ItayB
ItayB

Reputation: 11367

git pull is actually a combination of: git fetch & git merge. You probably what to do the following:

  1. git checkout master # switch to master branch on your local repo.
  2. git status # make sure you are clean
  3. git pull # get last commits from remote repo
  4. git checkout <your-branch> # switch back to your side branch
  5. git merge master # merge the master commits into your-branch
  6. optionally: git push origin <your-branch> # to backup your commits/updates in remote repo

Upvotes: 1

Oxymoron
Oxymoron

Reputation: 1452

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/

Upvotes: 0

kovalenko-alex
kovalenko-alex

Reputation: 183

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

Upvotes: 1

Related Questions