'Lost git folder and repo information
I have a gitHub repo and I recently copied my local folders to a different machine/hard drive. This is a Windows 10 Pro laptop.
I made some changes to the local files, and would like to push to the GitHub repo. I did:
git add *
and I get back:
fatal: not a git repository (or any of the parent directories): .git
How do I re-initialize, and push to GitHub
Solution 1:[1]
I see two ways you can solve it easily:
Clone the repo again to another folder, and copy the changed from the old to the new folder, then work normally on this new folder. (or rename the old folder)
Clone the repo again to another folder, and copy the
.git
folder from the new to the old folder, as suggested here.
Otherwise, you'd have to work around with a few more commands, make a safety backup before so you don't mess your code accidentally etc. I'd go with the first, simpler choice.
Solution 2:[2]
Do you still have access to the old computer? It seems that .git/
folder (and .gitignore
file if you had one) wasn't copied. They are hidden files so you would need to first locate them. If you have them on your old machine, they should be in the same folder as your code.
Link> How to show hidden files on win10
Once you locate that .git/
folder, copy it to your new folder with the code.
Btw, maybe git add *
is not the best idea. => Explanation
I would suggest:
git status
to first check which files you are addinggit add -A
(if you want to add all of them at once)git commit -m 'Your git commit message'
git push origin HEAD
(by usingHEAD
, you actually push from whichever current branch you are on - no need to type the branch name)
P.S. Note that IF you have been changing/modifying files on your new machine (and in case .git/
wasn't copied indeed), there is nothing which could have tracked all those changes. Thus, there will be nothing to commit.
P.P.S. If you already have recent version of files on GitHub, that can be helpful. I would be glad to help you but please provide more info on what exactly happened, what do you have access to, etc.
Good luck, N.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | George |
Solution 2 | Ratnanil |