Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git sparse checkout for simple web deployment

I have a directory structure like this:

../dir1/dev/project1/...
           /project2/...
           /project3/...
       /production/

I have dev (and all its sub directories) checked into git (and github). All is working well.

I would like to use github to deploy only project2 by checking out (or pulling, or whatever) into my production directory. (And specifically, I want to check out by tag.) So this would result in ../dir1/production/project2

I'm not a git expert but have read a bunch online and it seems that a 'sparse checkout' is what I'm after. I've tried various combinations of the instructions here and here and here.

Basically I did:

mkdir <repo> && cd <repo>
git init
git remote add –f <name> <url>
git config core.sparsecheckout true
echo /project2/ >> .git/info/sparse-checkout

When I do git pull <remote> TAGNAME I get fatal: The remote end hung up unexpectedly.

When I do git checkout TAGNAME I get error: Sparse checkout leaves no entry on working directory.

What am I doing wrong?

like image 861
Ross R Avatar asked Apr 05 '13 06:04

Ross R


1 Answers

Aha - solved it. The problem was that by doing init it was creating an empty repository, so I couldn't do a checkout. (I don't know why the pull didn't work.)

Instead, do a clone , but use the -n parameter for "no checkout". This clones the git repository but leaves your working tree empty. Then set up sparse checkout. Then checkout just what you want.

To whit:

cd <parentdir>
git clone -n <url>
cd <repo_dir>
git remote add –f <name> <url>
git config core.sparsecheckout true
echo /<foldername>/ >> .git/info/sparse-checkout
git checkout <tagname>
like image 88
Ross R Avatar answered Oct 16 '22 04:10

Ross R