Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

(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'
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading