How to Pull All Branches in Git

Abdul Jabbar Feb 02, 2024
  1. Fetch Origin Branches in Git
  2. Pull Origin Branches in Git
  3. Fetching All Branches in Git
  4. Pulling All Branches in Git
How to Pull All Branches in Git

Git provides us a platform where we can maintain several separate development commits for a new project known as branches. We can recover the recent version of the branch from a remote repository as we want or recover all branches at once according to the current requirements.

The important work that we do daily on the remote branch is non-other than downloading.

The remote data that we are working with is worth downloading, or we can say it’s vital to download it because it is similar to a snapshot. It is as up to the mark as previously because we precisely downloaded data from the remote branch using the fetch or pull command.

This fact should not be forgotten while examining remote branches and commits.

This article will discuss how to apply the git fetch -all and git pull -all command to recover changes from a remote repository.

Fetch Origin Branches in Git

$ git fetch origin

The git fetch command only downloads new features from a remote repository. It does not combine any of these new features into our recent working files.

With fetch, we can get an updated view of entire commits pushed in a remote repository. As it’s harmless, we are assured that fetch will never control and might ruin anything in the current local branch.

Pull Origin Branches in Git

$ git pull origin master

The git pull command is used to upgrade our present HEAD branch with the new commits from the remote repository. This means that pull is not only based on downloading a new feature but also clearly combining it into our recent working copy files.

The outcome of git is as follows.

  • As we know, git pull makes an effort to combine remote changes with our local files, which may result in a merge conflict in the local branch.
  • Unlike fetch, it’s safe enough to begin a git pull only with a clean working copy. This clarifies that we should not make any uncommitted local changes before we pull in the local branch.

Fetching All Branches in Git

For fetching all branches from all remote repositories, we will run the command git fetch with the --all option:

git fetch --all

Pulling All Branches in Git

It is safe with the help of the git fetch command to update local copies of the remote repositories, but the problem is that it doesn’t upgrade local branches.

For updating the local branch, we need to pull each branch. This can’t be performed using fetch so that we will achieve it manually.

For updating local branches, which will track remote branches, we’ll run the git pull command with the --all option:

git pull --all

However, this can be executed only for local branches which track remote branches. For tracking all remote branches, we will execute the following command before git pull:

git branch -r | grep -v '\->' | while read remote; do git branch --track 
Author: Abdul Jabbar
Abdul Jabbar avatar Abdul Jabbar avatar

Abdul is a software engineer with an architect background and a passion for full-stack web development with eight years of professional experience in analysis, design, development, implementation, performance tuning, and implementation of business applications.

LinkedIn

Related Article - Git Pull