2

Is there any git command that allow me to "clone" from a git repository but only the working directory of specified branch is cloned without .git folder that has all logs and version history?

There are few reasons to work with multiple working directory on single .git repo. Reason 1: I have few branch in a git, I want to work and see these branch at the same time without git checkout that may override files in branches. Reason 2: I want to make a software release of particular branch but don't want to disturb the branch that I am working.

manojlds
  • 290,304
  • 63
  • 469
  • 417
Chau Chee Yang
  • 18,422
  • 16
  • 68
  • 132
  • 1
    What are you trying to achieve? – manojlds Jul 18 '11 at 04:06
  • Are you trying to replicate the behavior of `svn export` ? If so, see here: http://stackoverflow.com/questions/160608/how-to-do-a-git-export-like-svn-export – Rob Allen Jul 18 '11 at 04:07
  • 1
    http://stackoverflow.com/questions/2866358/git-checkout-only-files-without-repository might help you. – vinod Jul 18 '11 at 04:08
  • Manojlds: There are few reasons to work with multiple working directory on single .git repo. Reason 1: I have few branch in a git, I want to work and see these branch at the same time without git checkout that may override files in branches. Reason 2: I want to make a software release of particular branch but don't want to disturb the branch that I am working. – Chau Chee Yang Jul 18 '11 at 04:23
  • Why don't you make another clone ( or just copy the existing repo) and checkout another branch in that? I have said the same in my answer, you can comment there. I have update your question with the above comment. – manojlds Jul 18 '11 at 04:29
  • An extra clone will require push/pull to sync between repositories. More over, a clone will have extra .git folder to store history/logs. – Chau Chee Yang Jul 18 '11 at 05:19
  • Clones on a single filesystem will use hardlinks for the blob files, which means that you'll use little extra disk space or time in cloning. – Phil Miller Jul 18 '11 at 08:07
  • There's also some way to have a work tree separated from its repository directory, but I can't seem to find the script at the moment. – Phil Miller Jul 18 '11 at 08:08
  • Novelocrat: I come across this: "git --work-tree=new-working --git-dir=/.git checkout ." It works in normal git repository, but it need some work on project that has submodules – Chau Chee Yang Jul 18 '11 at 08:46

2 Answers2

3

As per OP's latest comment:

Why don't you make another clone ( or just copy the existing repo) and checkout another branch in that?

Git-Archive can help you:

Sample from the docs:

git archive --format=tar --prefix=junk/ HEAD | (cd /var/tmp/ && tar xf -)

You can also use the --remote flag to get it from a remote archive.

http://www.kernel.org/pub/software/scm/git/docs/git-archive.html

manojlds
  • 290,304
  • 63
  • 469
  • 417
3

On Linux (or Windows too, if you install a commandline tar client):

git archive <commitish> | tar -x -C /path/to/folder

Basically, this tells git to build an archive (tarball) of the source tree at revision <commitish> and then pipes it through tar which extracts it into a folder.

Unfortunately, git doesn't currently support this directly.

Matthew Scharley
  • 127,823
  • 52
  • 194
  • 222
  • I don't understand why this question is downvote. Perhaps someone don't like my question at all. – Chau Chee Yang Jul 18 '11 at 04:26
  • Matthew: git archive might help but I need extra untar operation to extract the source. This is inconvenient if I use git in Windows. – Chau Chee Yang Jul 18 '11 at 04:27
  • @Chau Chee Yang: Totally agree with you, unfortunately this is the only solution as `git` doesn't have an operation analogous to `svn export` built into it. – Matthew Scharley Jul 18 '11 at 04:52