乐闻世界logo
搜索文章和话题

How do I fetch only one branch of a remote Git repository?

1个答案

1

To clone a single branch from a remote Git repository, use the git clone command with the --single-branch option. This allows you to clone only the specified branch, rather than all branches in the repository. This method saves time and storage space, especially when the remote repository contains numerous branches and data.

The specific steps are as follows:

  1. Open your terminal.

  2. Use the git clone command with the --single-branch option, specifying the branch name and the remote repository URL. The format is:

    bash
    git clone --single-branch --branch <branch_name> <repository_url>

    Where <branch_name> is the name of the branch you want to clone, and <repository_url> is the URL of the remote repository.

For example, if you want to clone the dev branch from a GitHub repository with the URL https://github.com/example/repo.git, the command would be:

bash
git clone --single-branch --branch dev https://github.com/example/repo.git

This command creates a local directory named repo containing only the content of the dev branch.

This method is ideal for quickly obtaining a specific branch for development or testing purposes.

2024年8月8日 09:27 回复

你的答案