Refreshing a git bare clone
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?
git gc
will clean up any unreachable commits.
It looks like you're running commands inside the usb-mounted directory. If this is the case, then I'd suggest that you take a different approach. Use git push
from your working directory to update the usb repository, and git pull
when you move it to the other machine. This will take care of ensuring that everything is up to date on the usb repository. Don't run anything from inside the usb-mounted directory.
By the way, git fetch
should pull in new branches. If it isn't then there is something else wrong.
Instead of using --bare
switch for cloning use the --mirror
one.
Then git fetch
will do the job.
Discussed here
git fetch
does fetch new branches.
Do a git push
to the bare repo from your working / main repo as an alternative.
精彩评论