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.
Asked
Active
Viewed 86 times
0
-
https://stackoverflow.com/search?q=%5Bgit%5D+clone+into+non-empty – phd Jun 14 '22 at 07:43
-
Note that the short version of all of these is "you don't"—that is, you don't run `git clone`. You still *get* a clone, you just don't do it using a simple `git clone` command. You mix together some set of *other* Git commands (possibly including a `git clone` into an empty directory). – torek Jun 14 '22 at 09:20
1 Answers
2
(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'

LeGEC
- 46,477
- 5
- 57
- 104