I'm using a git bare repo on a usb storage as a transport mechanism for work between different locations. I initiated the usb storage by doing:
git clone --bare /path/to/clone
The question is how to refresh the clone (i.e. the get the equivalent result of a new clone) without erasing the old clone and doing a new one.
Just doing git-fetch isn't enough for the following reasons:
- git-fetch doesn't fetch new branches
- If the source did a rebase or commit -amend then the usb-clone will still contain the old commits.
The first issue may be solved by the following script:
git fetch --prune origin -- \
`git ls-remote -h origin | while read sha ref; do echo "+$ref:$ref"; done`
(See: http://git.661346.n2.nabble.com/How-to-fetch-all-remote-branches-from-remote-td3380849.html)
But how can the second issue be solved? How can I erase commits that no longer exist on the remote?