Git tricks

  1. Backup an entire repository to one file using git bundle:

    git bundle create BACKUPFILE.git --all --tags --remotes
  2. Backup an entire local repository (with cache etc.) using rsync

    rsync -hxPavilyzH --stats --delete .git/ USER@HOST:/PATH/TO/BACKUP.git/
  3. Automatically clean the repository of unneccesary files using git gc

    > du -chs .git
    17M     .git
    17M     total
    > git gc
    Counting objects: 12937, done.
    Compressing objects: 100% (7859/7859), done.
    Writing objects: 100% (12937/12937), done.
    Total 12937 (delta 5145), reused 12515 (delta 4872)
    Removing duplicate objects: 100% (256/256), done.
    > du -chs .git
    15M     .git
    15M     total