📌  相关文章
📜  来自特定分支的 git clone - Shell-Bash (1)

📅  最后修改于: 2023-12-03 15:26:34.854000             🧑  作者: Mango

Git Clone from a Specific Branch - Shell/Bash

Introduction

In Git, clone is a command used for copying a repository to a local machine. By default, git clone copies all the branches present in the repository. However, sometimes, you may require only a specific branch of the repository. In this tutorial, we will discuss how to clone a Git repository with only a particular branch.

Clone a Git Repository with a Specific Branch

To clone a Git repository with only a specific branch, we need to specify the branch name along with the repository URL in the git clone command. Here's an example command:

git clone -b branch-name repository-url.git

In the above command, branch-name is the name of the branch we want to clone, and repository-url.git is the URL of the repository we want to clone.

Let's say, we want to clone the develop branch of the my-repo repository. The command would be:

git clone -b develop https://github.com/user/my-repo.git

This will only copy the develop branch to the local machine and exclude all other branches.

Conclusion

In this tutorial, we have learned how to clone a Git repository with only a specific branch. This can be useful when we only require a particular branch and do not want to clone all the branches of a repository.

Happy Coding!