This study will discuss the method of copying the remote branch to the local branch in Git.
How to Copy Remote Branch to Local Branch in Git?
While making a copy of a remote branch, copy its content to a local branch but do not make any tracking relation with them.
To copy the remote branch to the local branch in Git with the specified purpose, follow the below procedure.
Step 1: Open Git Bash
Open up the “Git Bash” terminal on your system using the “Startup” menu:
Step 2: Navigate to Git Directory
Move to the Git repository where you want to place the copy of the remote branch:
Step 3: Check Branches
Execute the “git branch” command to check the list of all remote and local branches that exist in the Git repository:
As you can see in the image below, our local repository contains “copy_branch”, “main”, and “master”, and two remote branches:
Step 4: Create Branch Copy
Create a copy of the remote branch in the local repository using the “git switch” command with the “-c” option. For instance, we want to create a copy of the “origin/copy_branch” remote branch, and the “new_copy_branch” is the name specified for the copied branch that is going to be placed in the local repository:
Step 5: Check Branches List
After doing so, run the simple “git branch” command to check the list of local branches:
The given output indicates that we have successfully copied the remote branch as “new_copy_branch” in the current directory:
Or, run the “git branch” command with “-a” flag to enlist all remote and local branches:
We have provided the process of copying the remote branch to the local branch in Git.
Conclusion
To copy the remote branch to the local branch in Git, first, open the Git Bash, and navigate to the local directory. Then copy the remote branch locally using the “$ git switch -c” command and switch to it. After that, check the Git local branches list by executing the “$ git branch” command to verify the newly copied branch. In this study, we have discussed the method of copying the remote branch to the local branch in Git.