🔀 Git & GitHub Intermediate

What is git archive?

Why Interviewers Ask This

Mid-level Git & GitHub roles require deep understanding of this topic. Interviewers ask this to separate candidates who truly understand the mechanics from those who only know surface-level concepts.

Answer

git archive creates an archive (zip or tar) of a Git tree without including the .git/ history directory. Useful for distributing source code releases without the full Git history. Usage: git archive --format=zip HEAD > release.zip — create a zip of current HEAD; git archive --format=tar.gz --prefix=myproject/ v1.0 > myproject-v1.0.tar.gz — archive a specific tag with a directory prefix inside the archive; git archive HEAD src/ > src.zip — only archive the src/ directory; git archive HEAD:src/ > src.zip — archive the contents of src/ (no src/ prefix in archive). --prefix adds a directory prefix to all files in the archive (common for release tarballs where you want myapp-1.0/ at the root). Remote archive: git archive --remote=https://github.com/user/repo.git HEAD > archive.zip (requires server support). .gitattributes can mark files with export-ignore attribute to exclude from archives (e.g., tests, docs, CI config that aren't needed in a source release).

Common Mistake

Candidates often give textbook answers here. Interviewers are more impressed when you relate the concept to a specific problem you solved in a real Git & GitHub project.