Skip to contentSkip to conversation

Easiest way to clone over an existing directory?

DISCUSSION Josh Triplett 2 participants 2 messages Jun 16, 2016

lore
Share & tools
lore
#0 lore raw

Currently, every time I set up a new system, I run the following:

git clone $MY_HOMEDIR
mv home/.git .
rm -r home
git checkout -f

This seems like an odd dance to go through. But I can't just git clone into ~ directly, because git clone will not clone into an existing non-empty directory.

(I could use "git clone -n" to avoid the unnecessary checkout, but the files are small, and it wouldn't remove the need to rmdir so the number of commands would remain the same.)

Does some better way exist to handle this? And if not, would it make sense for git clone to have an option to clone into an existing directory (which should also avoid setting junk_work_tree)?

#1 lore raw
Quoted 11 lines · Josh Triplett

Currently, every time I set up a new system, I run the following:

git clone $MY_HOMEDIR
mv home/.git .
rm -r home
git checkout -f

This seems like an odd dance to go through. But I can't just git clone into ~ directly, because git clone will not clone into an existing non-empty directory.

Quoted 7 lines

(I could use "git clone -n" to avoid the unnecessary checkout, but the files are small, and it wouldn't remove the need to rmdir so the number of commands would remain the same.)

Does some better way exist to handle this? And if not, would it make sense for git clone to have an option to clone into an existing directory (which should also avoid setting junk_work_tree)?

My typical technique is something like the following:

git init
git remote add origin https://git.crustytoothpaste.net/git/bmc/homedir.git
git pull origin master

I'm not sure if that's the officially sanctioned way to do it, but it does work reliably.

Signature · 3 lines
brian m. carlson / brian with sandals: Houston, Texas, US
+1 832 623 2791 | https://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: https://keybase.io/bk2204