Git copy / export modified and new files to another directory as zip
Sometimes we need to copy / export the modified and new files in git to another directory for backup purposes. We can still use "stash" command or commit to different branch, but this one liner will help you copy the modified and new files to another directory as zip file.
This command lets you to create a backup of the changed or newly added files in the same structure as it is in git repository.

In this way we can avoid using "stash" command or committing into temporary branch to create the backup. May be helpful for someone!
This command lets you to create a backup of the changed or newly added files in the same structure as it is in git repository.
Syntax:
zip < path / filename.zip > $({ (git ls-files --others --exclude-standard) ; (git ls-files --modified)})
Example:
zip /home/john/project-backup-10-mar-2023.zip $({ (git ls-files --others --exclude-standard) ; (git ls-files --modified)})The above command will copy all the modified and new files in your repositary and compresses it as zip file called "project-backup-10-mar-2023.zip" in the "/home/john" directory.
Sample Output:

In this way we can avoid using "stash" command or committing into temporary branch to create the backup. May be helpful for someone!
Comments (0)