3

I am facing a problem with linking a local project to a git repository.

The problem started when i created a new folder with the same name of the git repository, then i ran git clone to get the source code locally. but what happened is that the repository downloaded and created inside the folder i created. so in order to run the application with the correct path, i cut the downloaded repository and i past it in the root and i deleted the main folder (linked to the master). now i made some changes in the applications and i want to link the folder to the git repository in order to push the changes.

as a result, i have a project and i want to link this project to an existing git repository.

Ali
  • 1,633
  • 7
  • 35
  • 58
  • Possible duplicate of [How do I clone into a non-empty directory?](https://stackoverflow.com/questions/2411031/how-do-i-clone-into-a-non-empty-directory) – phd Mar 18 '19 at 11:48
  • https://stackoverflow.com/search?q=%5Bgit%5D+clone+into+non-empty+folder – phd Mar 18 '19 at 11:48

1 Answers1

6

Probably the folder .git got lost during your cut&paste. It's an invisible folder.

Suggested approach to fix:

  1. Rename the current project folder to project-save
  2. Clone the project again. Make sure the folder structure is correct now.
  3. Copy all sources from project-save into the new project. You should now see a lot of "Overwrite?" questions. If you don't, something is wrong. "Yes to All" is your friend.
  4. Use Git to check that your modifications are there.
  5. Commit your modifications
  6. Delete project-save if you're sure that you got everything

Alternatively, you can use git remote add origin <url> to add <url> (replace with the correct URL of the remote repo) but that will fail when the .git folder was lost or has been corrupted.

Vikaton
  • 2,227
  • 3
  • 14
  • 23
Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820