How to Git Fetch a Remote Branch

Better Stack Team
Updated on June 24, 2024

To fetch a remote branch in Git, you can use the git fetch command followed by the name of the remote repository and the name of the branch you want to fetch. Here's how you can do it:

 
git fetch <remote-name> <branch-name>

Replace <remote-name> with the name of the remote repository (usually origin by default) and <branch-name> with the name of the branch you want to fetch.

For example, to fetch a branch named feature/branch from the origin remote repository, you would run:

 
git fetch origin feature/branch

Note:

  • Fetching a remote branch retrieves the latest changes from the remote repository without automatically merging them into your local branch.
  • After fetching the remote branch, you can check it out using git checkout or create a new local branch based on it using git checkout -b.
  • If you want to fetch all branches from the remote repository, you can simply use git fetch <remote-name> without specifying a specific branch name.