This write-up will guide you about downloading a branch from a remote repository.
How to Download Branch From a Remote Git Repository?
To download the branch from the remote repository, look at the below-provided steps:
- Navigate the local repository.
- Add a remote URL and verify it.
- Download the remote branch using the “git pull <remote-name> <branch-name>” command.
- View the downloaded remote branch.
Step 1: Redirect to Local Repository
First, write out the below-stated command and switch to the desired local repository:
Step 2: Add New Remote
Then, run the “git remote add” command with the remote repository’s URL and link the local repository with it:
Step 3: Verify Remote URL
Next, verify whether the remote URL has been added or not through the following command:
It can be observed that the local repository has been connected with the remote repository:
Step 4: Download Remote Branch
Now, type out the “git pull” command along with the remote and a particular remote branch name that needs to be downloaded. For instance, we want to download the remote “master” branch:
Here, the “–allow-unrelated-histories” option is utilized for telling Git that the user is allowed to combine the branches of both unrelated local and remote repositories:
Step 5: Verify Changes
Lastly, ensure whether the desired remote branch has been downloaded or not by displaying the remote branches:
Here, the “-r” option is utilized to list the available remote branches.
The below output displays the remote “master” branch, which indicates that the remote branch has been downloaded successfully:
We have explained the easiest procedure to download the branch from the remote repository.
To download the branch from the remote repository, first, redirect to the local repository. Then, connect the local repository with the remote repository and verify it. Next, execute the “git pull <remote-name> <branch-name>” command to download the desired remote branch from the GitHub repository. Lastly, view the downloaded remote branch using the “git branch -r” command. This write-up explained the method to download the branch from the GitHub repository.