How to copy a git repository directly form remote server without .git directory and .gitignore files?. In advance from a tag name or branch.
Asked
Active
Viewed 7,964 times
2 Answers
14
You can use the command
git archive branchname
to archive files from a named tree. I.e. you can pass the output to tar
to pack the files or filter files like .gitignore
(.git
will not be exported):
git archive branchname | tar -x -C c:\git-my-branch
Checkout out git help archive
for more details.
The equivalent of svn export . otherpath
inside an existing repo is
git archive branchname | (cd otherpath; tar x)
The equivalent of svn export url otherpath
is
git archive --remote=url branchname | (cd otherpath; tar x)

Sergey K.
- 24,894
- 13
- 106
- 174
-
Thanks. I am looking for something like last command (git archive --remote=url branchname | (cd otherpath; tar x)) But this is not working. For example following is not working git archive --remote=git@github.com:gihanshp/WordPress-Widget-Boilerplate.git master| cd /tmp/ – gihan Apr 27 '12 at 09:46
-
Have you tried the 'git archive branchname | (cd otherpath; tar x)'? – Sergey K. Apr 27 '12 at 09:48
-
-
1make a local copy first with 'git clone' and them use abovementioned commands. – Sergey K. Apr 27 '12 at 09:52
-
The reason is this. I want to get a copy of my project to the production server. The revision history is huge (about 1G). So I don't wan't to download that garbage in to production server and trying to speed up the process. Thanks anyway for your quick help. – gihan Apr 27 '12 at 09:59
-
2@gihan, see [this answer](http://stackoverflow.com/a/6538833/372643): use `--depth 1`. – Bruno Apr 27 '12 at 12:04
-
I tried "git archive develop --output=./develop.tar". Then when I do "tar tvf develop.tar" it only gives me abou 12 random files, not the entire develolp branch (which is huge). – John Little Nov 02 '20 at 07:58
0
I don't know if it helps, but my way is using scp recursively, ignoring hidden files:
scp -r {git_directory}/* {target_directory}
For example:
scp -r /local/yourProjectGit/* user@machine:/home/user/dist
scp -r /local/yourProjectGit/* /local/youtProyect/dist

Aitor
- 3,309
- 2
- 27
- 32