I am trying to make a simple backup script for my remotely hosted git repos. In the script I have a few lines that currently look like this:
git clone git@server:repo.git $DEST
tar czvf repo.tgz $DEST
rm -rf $DEST
Is there a way to make this all happen in one line? Can I pipe the git clone into the tar command? I don't need the cloned directory, I just want the compressed archive of it.
I've tried some experiments but can't seem to figure out the syntax.
The git archive command is a Git command line utility that will create an archive file from specified Git Refs like, commits, branches, or trees.
No you cannot just pipe git clone
because it does not write it out to the standard output. And why do you need a one-liner? They are great for boasting that you can do something cool in just one line, but not really ideal in real world.
You can do something like below, but you would not get .git
like you would in a git clone
:
git archive --format=tar --remote=git@server:repo.git master | tar -xf -
From git archive
manual
--remote=<repo>
Instead of making a tar archive from the local repository, retrieve a tar archive from a remote repository.
You can use git archive
for this purpose with the --remote
option.
You can pipe it to create zip or tar or whatever you like.
Please, see the git-archive(1) manual page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With