I have a local Git repository called \'skeleton\' that I use for storing project skeletons. It has a few branches, for different kinds of projects:
casey@aga
Similar to what @nosaiba-darwish said here: here
This is what we usually do in our company:
git clone -b <name_of_branch> --single-branch <git_url> folder_to_clone_locally
One way is to execute the following.
git clone user@git-server:project_name.git -b branch_name /your/folder
Where branch_name
is the branch of your choice and "/your/folder" is the destination folder for that branch. It's true that this will bring other branches giving you the opportunity to merge back and forth.
Update
Now, starting with Git 1.7.10, you can now do this
git clone user@git-server:project_name.git -b branch_name --single-branch /your/folder
Let us take the example of flask repo. It has 3 branches in addition to master. Let us checkout the 1.1.x remote branch
clone the git repo
git clone https://github.com/pallets/flask
cd into the repo.
cd flask
fetch remote branch 1.1.x
git fetch origin 1.1.x
checkout the branch
git checkout 1.1.x
You will switch to the branch 1.1.x and it will track the remote 1.1.x branch.
git clone --branch {branch-name} {repo-URI}
Example:
git clone --branch dev https://github.com/ann/cleaningmachine.git
{branch-name}
{repo-URI}
Using Git version 1.7.3.1 (on Windows), here's what I do ($BRANCH
is the name of the branch I want to checkout and $REMOTE_REPO
is the URL of the remote repository I want to clone from):
mkdir $BRANCH
cd $BRANCH
git init
git remote add -t $BRANCH -f origin $REMOTE_REPO
git checkout $BRANCH
The advantage of this approach is that subsequent git pull
(or git fetch
) calls will also just download the requested branch.
You can try the long-winded way:
mkdir newrepo.git
cd newrepo.git
git init
git remote add origin file:///path/to/original
git fetch origin branchiwant:refs/remotes/origin/branchiwant
git checkout -b branchiwant --track origin/branchiwant
What this does is:
Hopefully that will be something like what you are after.