git fetch --remote repository information fetch

You can use the git fetch command to fetch information about remote repositories. Think of it as synchronizing a remote repository to a local repository.

#Get remote repository information
git fetch

When do you use git fetch?

Using the " git pull" command will do a "git fetch" as well as any changes to the remote repository branch specified for the current branch. It will merge.

So if you want to use "git fetch" rather than "git pull", you don't want to merge the changes in the remote branch into the current branch.

For example, you may want to create a local branch based on a remote branch created by another developer, or manually merge a branch in a remote repository.

Also, for security reasons, some developers do not use "git pull" at all and do the merge work separately from "git fetch".

Please tell me what you should know with git fetch

The tags will be synced.

Distinguish between remote and local branches. When you do a git fetch, you fetch the remote branch into your local repository, but the remote branch and the local branch are different.

Remote branches have "origin" at the beginning, like "origin / foo".

Let's display the local branch with the git branch command.

#View local branch
git branch

Here is an example of the output of a local branch.

main
foo
bar bar

Let's display the remote branch with the "-r" option of the git branch command.

#View remote branches
git branch -r

Here is an example of the output result of a remote branch.

origin / foo
origin / baz

The tricky part is that a remote branch isn't a branch in a remote repository, but a branch in a local repository that points to a commit in a branch in a remote repository.

It's confusing, but think of "origin / foo" and "origin / baz" as being fetched into your local repository by "git fetch".

Associated Information