0

I was reading this post: What is the difference between 'git pull' and 'git fetch'?

and it said that once you do a "git fetch", you actually update your "remote-tracking branches under refs/remotes//".

If so, let's say that I have a branch named 'dev_branch' and it exists both on my local machine and on the remote server. If I do "git fetch", can I say that:

  1. No change will be made to local branch 'dev_branch' ?
  2. The branch 'origin/dev_branch' will be updated as the branch in remote server?

  3. If I do "git pull", I understand that it merges my local branch with the remote one. If I just opened a local branch that doesn't have a correspondent branch in remote server (let's call it my_branch), how will "git pull" affect it? Is it correct to say that it will not cause any change?

CrazySynthax
  • 13,662
  • 34
  • 99
  • 183

1 Answers1

2

For question 1 and 2. Yes, you are right. In case of

git fetch

There will be no change in your local dev_branch, git will only synchronize origin/dev_branch in your local computer with its counterpart in remote repository. This behaviour of git fetch is described clearly here. One way to verify this behaviour is by comparing:

git diff origin/dev_branch dev_branch

For question 3, if there is no origin/my_branch in remote repository and you invoke

git pull

Git will prompt error:

fatal: No remote repository specified. Please, specify either a URL or a remote name from which new revisions should be fetched.

You can specify the remote branch, you'd like to merge change with you local my_branch by:

git pull remote_repository remote_branch_name

And run git log to see the effect:

Merge branch 'remote_branch_name' of git_on_the_cloud_service/remote_repository

Son Nguyen
  • 170
  • 3
  • 6