Explore Courses Blog Tutorials Interview Questions
+3 votes
in DevOps and Agile by (29.3k points)
edited by

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@agave [~/Projects/skeleton] git branch

* master




If I want to check out the master branch for a new project, I can do

casey@agave [~/Projects] git clone skeleton new

Initialized empty Git repository in /Users/casey/Projects/new/.git/

and everything is how I want it. Specifically, the new master branch points to the skeleton master branch, and I can push and pull to move around changes to the basic project setup.

What doesn't work, however, is if I want to clone another branch. I can't get it so that I only pull the branch I want, for instance, the rails branch, and then the new repository has a master branch that pushes to and pulls from the skeleton repository's rails branch, by default.

Is there a good way to go about doing this? Or, maybe this isn't the way that Git wants me to structure things, and I'm certainly open to that. Perhaps I should have multiple repositories, with the Ruby on Rails skeleton repository tracking the master skeleton repository? And any individual project cloning the Ruby on Rails skeleton repository.

1 Answer

+4 votes
by (50.2k points)
edited by

In git 1.7.10 it allows the user to clone a single branch using:

git clone --single-branch

as in:

git clone <url> --branch <branch> --single-branch [<folder>]

And since Git 1.9.0, shallow clones support data transfer (push/pull) using:

git clone --depth 1

so this option is even more useful now. And this is the easiest way to reduce the bandwidth.


For more commands like this please go through the following tutorial that will help you understand the git

Browse Categories