Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git clone into a branch

Tags:

git

Is it possible to clone a project into a new branch ? I have already cloned the main repo and would like to clone another repo that is a fork of it into a branch. I want to be able to keep comparing the differences using git diff. How can this be done ?

like image 480
DavidL Avatar asked Aug 03 '12 20:08

DavidL


People also ask

How do I clone into a branch?

You can clone a specific branch from a Git repository using the git clone –single-branch –branch command. This command retrieves all the files and metadata associated with one branch. To retrieve other branches, you'll need to fetch them later on.

Can we clone specific branch?

There are two ways to clone a specific branch. You can either: Clone the repository, fetch all branches, and checkout to a specific branch immediately. Clone the repository and fetch only a single branch.


1 Answers

You can specify a new remote and then call git fetch:

git remote add fork git://example.com/repo.git
git fetch fork

You can then compare branches with

git diff origin/master fork/master
like image 157
knittl Avatar answered Oct 13 '22 03:10

knittl