Bootstrap FreeKB - Git (Version Control) - Create an archive (zip gzip bzip2)
Git (Version Control) - Create an archive (zip gzip bzip2)

Updated:   |  Git (Version Control) articles

The most basic way to use Git is to use the git clone command to clone an origin Git repository (such as example.git) to a directory on your PC (such as /home/john.doe/git), make a change to a file in the cloned repository on your PC (such as example.txt), use the git commit command to commit the change to the file, and to then use the git push command to upload the file to the origin Git repository.

 

The git archive command can be used to create an archive, such as zip, gzip, or bzip2 archive. In this example, a gzip archive named example.tar.gz is created of the master branch of the foo.git repository.

git archive --remote ssh://git@bitbucket.example.com:7999/path/to/foo.git master --format tar.gz --output /path/to/example.tar.gz

 

Or like this.

git archive --remote ssh://git@bitbucket.example.com:7999/path/to/foo.git master | gzip > example.tar.gz

 

Let's say the foo.git repository contains two directories, "foo" and "bar". Here is how you could create an archive of only the "bar" directory.

git archive --remote ssh://git@bitbucket.example.com:7999/path/to/foo.git master bar/ | gzip > example.tar.gz

 

Be aware that apparently this cannot be done with a GitHub repo. For example, this will return some weird errors.

git archive --remote ssh://git@github.com:acme/path/to/foo.git master bar/ | gzip > example.tar.gz

 

So, for GitHub repos, I would instead just clone the repo and then create a TAR archive from the clone, something like this.

git clone git@github.com:foo/bar.git /tmp/foo
tar -zcpf my.tar /tmp/foo
rm -rf /tmp/foo

 

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter e34289 in the box below so that we can be sure you are a human.