How To Clone Specific Git Branch

Channel: Linux
Abstract: you have learned to clone a specific Git branch from a remote repository like GithubGit is commonly used as a version control system for any applicati

Git is commonly used as a version control system for any application. Which is helpful for tracking changes in any set of source files. A branch in Git represents an independent line of development with a unique set of code changes with a unique name.

This tutorial will help you to clone a specific branch from the remote Git repository.

Clone Specific Git Repository

You can clone any remote repository with git clone command. The default clones the master (main) branch from remote. You can also specify the branch name with -b option to clone a specific branch.

git clone -b 5.8-branch https://github.com/WordPress/WordPress.git 

The above command clones the specific branch but fetches the metadata of other branches. You can view all branches details with command git branch -a.

To skip metadata of other branches use --single-branch option like:

git clone -b 5.8-branch --single-branch https://github.com/WordPress/WordPress.git 

That’s it. Switch to the newly created directory and type git branch to check the branch.

Conclusion

In this write-up, you have learned to clone a specific Git branch from a remote repository like Github, Gitlab, Bitbucket, or a self-hosted Git server.

Ref From: tecadmin
Channels: git branchgit

Related articles