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.

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

community@betterstack.com

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github