In addition to @ThiefMaster:
I like to
git clone --mirror
or
git push --mirror
to update all (local & remote) branch refs and tags
Additional info As noted, --mirror will really replicate the repo as is, thus overwritany changes in the destination. Branches that do not exist in the source will get pruned unconditionally.
Essentially, it is like working with a remote and doing 'git remote update --prune', the difference being that the branches affected can be local branches as well as 'remote' refs[1]
@LeSpocky (and others?)
Now if changes disappear, they will never generate merge problems, so that's easy.
--mirror
is named after the real-life concept, so it was designed to pave over any differences in the target. If the target is non-bare, and you had local changes committed, you can always get them back via the reflog of the target's local branch (git log -g
, git reflog
).
As a general safety measure you could have a hook to 'git stash save' in the target.
Keep in mind though, that --mirror was designed to, well, mirror and this question was in fact on how to replicate all branches to a bare remote. :)
[1] (the refs are there, but the remote definitions don't get copied; if you want that, do a manual copy from .git/config to .git/config on the push destination)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…