I did a backup of my “Code“ folder while switching computers and my (custom) backup tool didn’t copy .git folders. So I have folders with an (usually) up-to-date working directory, but that aren’t tracked by git in any way.
For repos that have been pushed to a remote, can I “clone“ just the .git directory and transform my folders into actual local git repos?
What I tried already:
git initthen adding the remote,fetching and trying to merge or rebase in various ways (the new repo is empty so doesn’t even have a single commit)git clone --bare ...into another folder, then renaming that folder to.git.gitdoesn’t consider the working directory to even be a git repo.
1 Answer
My usual approach for this situation:
- clone the repo into a fresh folder
foobar, ensuring I have checked out the proper branch - delete everything except the
.gitfolder - copy the existing files into the
foobarfolder
If you're not checking out the proper branch before replacing the repo content, you can still select the branch using git reset commands.