How to create Git archive
Hey there! I’m Srebalaji. You are receiving this email because you have subscribed to level up your game in Git.
Git archive helps you to archive file from the repository.
The archive file will contain all the files and folders of the repository without Git metadata.
You can use that archive file to back up your project or attach it to the release notes.
How to use it
You can create a Git archive from the specific commit, branch, or from the tag.
The Git archive will stream the output to stdout. We have to specify the output format precisely.
And it needs to specify the format as well. Four formats are supported but the popular options are tar and zip.
git archive --format=zip --output=backup.zip HEAD
The above command is taking HEAD commit as the reference for the archive and generates the zip file that contains all the files and folders of the repository.
Git will be able to identify some of the formats itself from the output parameter.
git archive --output=V1.0.tar.gz 374934c
The above will create a tar file from the specified commit.
You can also archive only the specific directories from the repository.
git archive --output=V1.0.zip main_branch ./build
The above command will take the archive from the main_branch and will create the archive file from only the build directory. Other files and directories are neglected.
That’s all for this week.
See you next week :)