Git Fetch
The git fetch
commands helps users download commits, refs and files from the remote repository to the local repository. These commits are done by the teammates and people associated with the project in the organization or maybe the user itself directly on the remote repository. In other words, executing git fetch
command will help you see the updates from all the teammates on the repository.
git fetch
does not hurt your working repository at all. The git fetch
command is a great way to stand at a place from where you can see the changes and decide if you want to keep them or discard them. Keeping the changes is called merging in Git and it is an explicit operation. So until you press git merge
, you won’t be adding anything.
Git Fetch Common Usage
git fetch <repository url>
: To fetch the complete remote repository.Example:
git fetch gitopia://gitopia147dgrtq5ywww473uz680fx2ucex9fv3qnw94zm/hello-world
Output:
From gitopia://gitopia147dgrtq5ywww473uz680fx2ucex9fv3qnw94zm/hello-world
* branch HEAD -> FETCH_HEADgit fetch <branch URL><branch name>
: To fetch a specific branch from a repository.Example:
git fetch gitopia://gitopia147dgrtq5ywww473uz680fx2ucex9fv3qnw94zm/hello-world dev
Output:
From gitopia://gitopia147dgrtq5ywww473uz680fx2ucex9fv3qnw94zm/hello-world
* branch dev -> FETCH_HEADgit fetch --all
: To fetch all the branches simultaneously from a remote repositoryExample:
git fetch --all
Output:
Fetching origin
From gitopia://gitopia147dgrtq5ywww473uz680fx2ucex9fv3qnw94zm/hello-world
* [new branch] master -> origin/master
* [new branch] dev -> origin/devgit fetch origin
: To synchronize the local repository.Example:
git fetch origin
Output:
From gitopia://gitopia147dgrtq5ywww473uz680fx2ucex9fv3qnw94zm/hello-world
* [new branch] dev2 -> origin/dev2You can learn more about the
git fetch
command and its options in git-scm's documentation.