This blog illustrated the process of the Git shallow checkout remote branch.
How to Git Shallow Checkout a Remote Branch?
To Git shallow checkout a remote branch, check out the following steps:
- Navigate to the Git particular directory.
- Check the list of remote URLs.
- Clone the remote repository with the specified depth and fetch it.
- Display all existing branches including local and remote.
- Use the βgit checkout <remote-branch>β command.
Step 1: Switch to Git Repository
First, go to the Git local repository by running the below-stated command:
Step 2: View Remote URL List
Then, execute the βgit remoteβ command to show the list of the remote URL:
Step 3: Git Clone With Depth β1β
Next, clone the Git remote repository by utilizing the βgit cloneβ command along with the desired depth β1β:
As a result, the most recent remote commit will be cloned from the GitHub server:
Step 4: git fetch With Depth β1β
After that, run the βgit fetchβ command to download the latest version of the Git remote repository:
Here, the β-v –depth=1β option is used to hold the amount of data we downloaded:
Step 5: List All Branches
Now, show the list of all existing branches including local as well as remote by using the βgit branchβ command with the β-aβ option for all:
As a result, all branches will be displayed. Now, select the desired remote branch. For instance, we have selected the βremotes/origin/featureβ branch:
Step 6: Checkout to Remote Branch
After that, execute the βgit checkoutβ command and switch to the remote branch:
It can be seen that the HEAD is now moved to the β1a5ebb4β SHA-hash:
Step 7: View Branches List
Lastly, run the βgit branchβ command along with the β-vvβ option to view the all branches along with the HEAD pointer detail:
According to the below-provided output, the HEAD pointing to the remote βorigin/featureβ branch:
We have provided the easiest way to Git shallow checkout a GitHub remote branch.
Conclusion
To Git shallow checkout a remote branch, first, move to the Git particular directory and check the remote URL list. Then, clone the remote repository with the specified depth and fetch it. After that, view the list of all remote and local branches. Lastly, execute the βgit checkout <remote-branch>β command. This blog illustrated the process of the Git shallow checkout remote branch.