简体   繁体   中英

How to clone only a branch's working directory from a git repository without .git folder

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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM