The way I do this is to create a remote (bare) repository (on a separate drive, USB Key, backup server or even github) and then use push --mirror
to make that remote repo look exactly like my local one (except the remote is a bare repository).
This will push all refs (branches and tags) including non-fast-forward updates. I use this for creating backups of my local repository.
The man page describes it like this:
Instead of naming each ref to push, specifies that all refs under
$GIT_DIR/refs/
(which includes but is not limited torefs/heads/
,refs/remotes/
, andrefs/tags/
) be mirrored to the remote repository. Newly created local refs will be pushed to the remote end, locally updated refs will be force updated on the remote end, and deleted refs will be removed from the remote end. This is the default if the configuration optionremote.<remote>.mirror
is set.
I made an alias to do the push:
git config --add alias.bak "push --mirror github"
Then, I just run git bak
whenever I want to do a backup.