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

Cloning into an existing, non-empty directory?

From
Richard Hartmann <richih.mailinglist@gmail.com>
Date
Apr 21, 2011, 21:27 UTC
Message-ID
<BANLkTi=VwiqN99AMEJb6jb1uFya2Hipibw@mail.gmail.com>
Hi all,

I know that the manpage explicitly states that it's not possible to clones into an existing, non-empty directory, but I wanted to see if anyone is aware of a workaround or if I can convince people that is it of use in specific circumstances.

Some of you will be keeping their RC files in git repo(s) which means you are basically left with two options:

1) Use soft-/hardlinks
2) Change your working tree
I went for option two which looks like:
richih@roadwarrior ~/.config/vcsh/repo.d/mr.git % ls -a
.   branches        config       FETCH_HEAD  hooks  info  objects    packed-refs
..  COMMIT_EDITMSG  description  HEAD        index  logs  ORIG_HEAD  refs
richih@roadwarrior ~/.config/vcsh/repo.d/mr.git % cat config
[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
	worktree = /home/richih/
[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = <remote>
[branch "master"]
	remote = origin
	merge = refs/heads/master
richih@roadwarrior ~/.config/vcsh/repo.d/mr.git %
This works just fine as long as you're using
  git --work-tree=$HOME \
    --git-dir=$HOME/.config/vcsh/repo.d/mr.git \
    pull

or similar on an existing, manually mangled repo. 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.

Obviously, this would imply some sort of conflict handling during cloning.

Anyway, I would _really_ love to have a way to avoid all this manual work and just clone into $HOME, telling git that it's OK and I know what I am doing.

Thanks, Richard

PS: In case you are interested in keeping your RC files (and the rest
of your life) in git, there's a vcs-home mailing list and #vcs-home on
irc.oftc.net.
Next: Jonathan Nieder
Message 1 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.