git fetch and git pull command in Git

1. git fetch

The git fetch allows us to download changes from a remote repository, BUT those changes will not be automatically integrated into our working files. It lets us see what others have been working on, without having to merge those changes into our local repo.

Syntax Scenario 1: To fetch the remote repository: Syntax git fetch <remote> This command fetches all the branches and history from a specific remote repository. It only updates remote tracking branches. For example, git fetch origin would fetch all changes from the origin remote repository. If remote is not specified, defaults to origin. Scenario 2: To fetch a specific branch:
We can also fetch a specific branch from a remote using the git command below: Syntax git fetch <remote> <branch> For example, git fetch origin master would retrieve the latest information from the master branch on the origin remote repository.

2. git pull

The git pull is another command we can use to retrieve changes from a remote repository. Unlike fetch, pull actually updates our HEAD branch with whatever changes are retrieved from the remote.

Syntax git pull <remote> <branch>

git pull origin master would fetch the latest information from the origin's master branch and merge those changes into our current branch.