git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Cloning into an existing, non-empty directory?

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Apr 21, 2011, 22:03 UTC
Message-ID
<20110421220327.GA3396@elie>
In-Reply-To
<BANLkTi=VwiqN99AMEJb6jb1uFya2Hipibw@mail.gmail.com>
Hi,
Richard Hartmann wrote:
Show 13 quoted lines
> The only real
> problem left is that I can't clone initially as $HOME is obviously
> non-empty, resulting in
>
>   git --work-tree=$HOME \
>     --git-dir=$HOME/.config/vcsh/repo.d/mr.git \
>     clone <remote> .config/vcsh/repo.d/mr.git
> fatal: working tree '/home/richih' already exists.
>
> This means I am down to cloning, creating the directories I need,
> moving .git and the actual files around, making git aware that tracked
> files were not deleted, just moved, and then finally being able to use
> my repo.
Have you tried something like the following?
	cd $CROWDED_DIRECTORY
	GIT_DIR=/path/to/git/dir
	GIT_WORK_TREE=$(pwd)
	export GIT_DIR GIT_WORK_TREE
	git init
	git remote add origin <remote>
	git pull
Two more caveats for the road. :)
 - git does not track detailed file permissions or secret/non-secret
   status.  Please be careful about ssh private keys and so on.
 - when updating the worktree, git will unlink existing files before
   replacing them and does not fsync the result.  So one should be
   careful when tracking files that will cause major harm if they go
   missing temporarily (though I can't think of any major examples in
   $HOME offhand).

Happy hacking, Jonathan

Previous: Richard HartmannNext: Richard Hartmann
Message 2 of 12 in “Cloning into an existing, non-empty directory?”
  1. Richard HartmannApr 21, 2011
  2. Jonathan NiederApr 21, 2011
  3. Richard HartmannApr 22, 2011
  4. Jonathan NiederApr 23, 2011
  5. Nguyen Thai Ngoc DuyApr 23, 2011
  6. Jonathan NiederApr 23, 2011
  7. Richard HartmannApr 23, 2011
  8. Jonathan NiederApr 25, 2011
  9. Andreas SchwabApr 25, 2011
  10. Jonathan NiederApr 25, 2011
  11. Jeff KingApr 25, 2011
  12. Richard HartmannApr 25, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.