Git archive of repository with uncommitted changes

How can I create an archive of the current repository including local uncommitted changes using git archive?

  • Failing to get package via composer require
  • git on UNC path
  • How to get colored output with git+mintty+mingw on windows?
  • How do I prevent a subdirectory from being matched in .gitignore?
  • Tips on upgrading CVS to git/hg?
  • Merge a range of revisions with Git or TortoiseGit
  • I do commit locally , and all is well , but when I push on GitHub, the commit it comes empty and files are have no changes. Why?
  • git + LaTeX workflow
  • Can't find git-svn on Mac OS X Leopard after installing via MacPorts
  • Will assigning at tag to a Github Release also assign it to the Commit
  • Creating a 'push prefix' for git
  • Gitolite has started giving me errors when I push to a Git repo with errors about “declined hooks”
  • 4 Solutions collect form web for “Git archive of repository with uncommitted changes”

    I know this is old, but I think I found a solution.


    stashName=`git stash create`;
    git archive <options> $stashName

    Since git wants a solid commit to make an archive, we can make a ‘one off’ commit using git stash. The create command just creates the stash commit (doesn’t reset your working directory or push it to the stash stack) and returns the hash for it.

    If you are worried about the space from the dangling commit, you can clean it up with a git gc --prune=now. Otherwise, just wait 2 weeks and it’ll disappear.

    Improving nevsan’s answer for my purpose – to archive latest code in any case (committed or not):

    uploadStash=`git stash create`; git archive -o ${uploadStash:-HEAD}

    If you haven’t committed the changes, then git archive won’t help you. If you just want a snapshot of your working area, tar is probably your best bet.

    Another solution with git ls-files :

    git ls-files | xargs tar -czvf archive.tar.gz
    Git Baby is a git and github fan, let's start git clone.