Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git how to clean a cloned repository and reclone

Tags:

git

windows

I am using a usb that i have cloned my repo, so i can transfer my work at home and vice versa. Many times the usb has problems and corrupts the repository. If I try to clean it and reclone it shows all the old (self) files as deleted, and all the origin's files as modified.

I tried to clean the cloned repo by deleting folder or rename it, or event delete .git and reclone but it still shows old files as deleted. Is there a way to fix it?

like image 532
dotoree Avatar asked Jan 31 '12 12:01

dotoree


2 Answers

I would really recommend, in order to have a clean version of your repo, to make a bundle.
(See git bundle man page).
Make sure you don't forget tags as well in your bundle.
Alternatives are discussed at "push vs. bundle vs. tar zcvf — to backup entire local .git".

That way, you get only one file to backup on your usb key (and you can clone/fetch from that bundle file).
One file is much harder to corrupt ;)

like image 179
VonC Avatar answered Sep 30 '22 11:09

VonC


You should be using a bare repository, that is one without a work tree, on the USB key. Bare repository is created with git init --bare or git clone --bare.

The "corruption" you are seeing is because git push does not update working directory of a non-bare target repository. If the working copy is checked out from the branch you are pushing, it will result in invalid state of the working copy.

However, there is absolutely no reason to have a working copy there unless you mean to work directly from the USB key. So just don't create it, it's not needed for anything.

If on the other hand you do intend to work off the USB key, either always pull to it (which does update the working copy, of course) or install appropriate hooks to update the working copy (there are two ways, depending on how you intend to work with it).

like image 34
Jan Hudec Avatar answered Sep 30 '22 09:09

Jan Hudec