Summary - Archive
- Git course
- Advanced
- Lesson 32/56
- 5 min
Combine the archive flow to prepare a distribution package.
Archive Workflow Summary
git archive produces clean distribution packages without including commit history or the .git folder. You can choose tar or zip with --format, set the destination file with --output, and package a specific branch or tag.
git archive --format=tar --output=surum.tar release
git archive --format=zip -o surum.zip v1.0.0With this tool, you create lean code packages for releases and server deployments without carrying redundant Git metadata.
Practice End-to-End Deployment Archive
Package the files in the prod branch of the repository referencing the prod branch with --format=tar and --output=dagitim.tar. Then list the files inside the archive with tar -tf dagitim.tar.
Starter code
git init -q
git config user.name "Dev"
git config user.email "dev@example.com"
echo "console.log('sunucu hazir');" > server.js
git add server.js
git commit -q -m "Sunucu hazirlandi"
git branch prod
git checkout -q -b test
echo "gecici test" > test.txt
git add test.txt
git commit -q -m "Test dosyasi"
# Dagitim paketini olustur ve listele:Sample solution
git init -q
git config user.name "Dev"
git config user.email "dev@example.com"
echo "console.log('sunucu hazir');" > server.js
git add server.js
git commit -q -m "Sunucu hazirlandi"
git branch prod
git checkout -q -b test
echo "gecici test" > test.txt
git add test.txt
git commit -q -m "Test dosyasi"
git archive --format=tar --output=dagitim.tar prod
tar -tf dagitim.tarExpected output
server.js
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Why is <code>git archive</code> preferred over <code>git clone</code> when deploying a Git repository to a production server?
- Because it increases repo size and speeds up the server
- Because it makes having Git installed on the server mandatory
- Because it provides a lean and secure package without .git history Correct answer
- Because it is a command that only works on local networks
Explanation: Packages created with `git archive` do not contain the `.git` directory or history; this keeps the size minimal and prevents sensitive history data from being pushed unnecessarily.
2 Create the Deployment Package
git archive --format=tar --output=app.tar ____
git archive --format=tar --output=app.tar prod
Explanation: To archive the `prod` branch as tar, pass the branch name directly at the end of the command.
3 Archive Features
| Term | Meaning |
|---|---|
git archive |
Creates clean source package |
--format=zip |
Compressed zip output |
--output |
Name of the file to create |
prod |
Target branch to package |