-1

Hello I am bit stuck with Git.

On my remote, I have merged my recent changes.

Now on my new branch which is br/register-page, I need to pull the latest changes from my repo.

What git command should I use? git pull? or git fetch?

Please help!

SwissCodeMen
  • 4,222
  • 8
  • 24
  • 34
  • I prefer to use *two* Git commands: `git fetch`, then `git merge`. You can, if you prefer, use *one* Git command: `git pull`. This runs the other two Git commands. The problems with using `git pull`—the all-in-one command—are similar in some ways to an all-in-one "buy can of food, open it, put in bowl, eat it" command: you can't tell in advance if the food was human food, or cat/dog food, or even poisonous-to-humans plant food, until you've already eaten it. Sure, you can take some ipecac afterward to barf it all up, but, yuck. – torek Oct 26 '21 at 19:54
  • https://stackoverflow.com/questions/292357/what-is-the-difference-between-git-pull-and-git-fetch – phd Oct 26 '21 at 23:57

2 Answers2

2

From the manual of the git pull command:

Incorporates changes from a remote repository into the current branch. In its default mode, git pull is shorthand for git fetch followed by git merge FETCH_HEAD.

So you need git pull.

git fetch downloads the changes but do not actually merge them in your local branches, which can be useful if you have some modification to do before but want to have the latest changes on hand.

OreOP
  • 122
  • 1
  • 5
1

If you have newest changes on master branch on remote, you could merge them to your existing branch locally by following commands:

git switch master
git pull
git switch br/register-page
git merge master

Or, even shorter, if you are on branch br/register-page:

git fetch origin master:master
git merge master
Michał Turczyn
  • 32,028
  • 14
  • 47
  • 69
  • But in the question isn‘t the speech of merging, only from pulling remote changes to local. So your code example are fine and right, but not that, what the questioner is looking for. – SwissCodeMen Oct 26 '21 at 15:30