Glam Prestige Journal

Bright entertainment trends with youth appeal.

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 init then 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. git doesn’t consider the working directory to even be a git repo.
1

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 .git folder
  • copy the existing files into the foobar folder

If you're not checking out the proper branch before replacing the repo content, you can still select the branch using git reset commands.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy