Initialize Git in a directory which is a repo too, just without .git

Advertisements

I have a repo, only that when I copied it over from another computer, I did not copy the .git directory. So, is there a way to initialize Git there and make it a working repo once again? I know how to do for non-repos, git initialize -> add -> commit -> push, but not certain about right steps in current scenario.

>Solution :

(preamble: to be on the safe side, make a backup copy of your directory, or make sure you already have that copy somewhere).


You can initialize a new empty repository, add the original central repo as a remote, and run git reset <some commit> (important note: without the --hard option) to set your active commit to where you want without modifying the files on disk :

git init

git remote add origin https://github.com/user/repo # <- add a remote
git fetch origin

# optional: set your current local branch to something other than master
git switch -c my/branch

git reset origin/my/branch   # <- regular reset, *not* 'reset --hard'

Leave a ReplyCancel reply