Search code examples
gitversion-controlgit-pullgit-fetch

Should I do git fetch before pull if branch exists locally?


I have following question about git.

I novice with git. I want to get last state of branch1 locally.

now I switched on branch2 and branch1 exists locally.

Now I make

  1. fetch
  2. switch to branch1
  3. pull

Please clarify me whether does first fetch redundant or not?


Solution

  • It is redundant. Quoting the docs:

    More precisely, git pull runs git fetch with the given parameters and calls git merge to merge the retrieved branch heads into the current branch.