Wednesday, January 15, 2025
HomeProgrammingHow do I clone a specific Git branch?

How do I clone a specific Git branch?

To clone a specific branch in Git, use the following command:

bash
git clone -b <branch-name> --single-branch <repository-url>

Here:

  • Replace <branch-name> with the name of the branch you want to clone.
  • Replace <repository-url> with the URL of the repository.
See also  Query comparing dates in SQL

The -b flag specifies the branch, and --single-branch ensures only that branch is cloned, saving space and time.

Example:

bash
git clone -b feature-branch --single-branch https://github.com/user/repo.git

If you’ve already cloned the repository, you can switch to another branch using:

bash
git checkout <branch-name>
RELATED ARTICLES
0 0 votes
Article Rating

Leave a Reply

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
- Advertisment -

Most Popular

Recent Comments

0
Would love your thoughts, please comment.x
()
x