Reputation: 655
Suppose I have a remote repository (such as on GitLab) already set up.
And I have a directory on my computer that is identical to that remote repository, but is not set up as a git repository.
How could I initialize my directory as a git repository, matching the existing remote, with its commit history etc?
In other words, how can I achieve the equivalent of cloning that repository, but using what I already have, instead of downloading everything again?
And if there are any differences with my directory, I would like them to be detected as changed and ready to commit.
The reason for this is that we are switching version control systems, so currently everyone in our team has the same project synchorized with Unity Collab. I initialized my copy and published it to GitLab, and I would like others to be able to enable the usage of git in their existing copy, without having to clone it again. Especially if they have changes in progess. Plus it lets them continue to use collab, as I've tested cloning and it breaks collab.
I found that copying my .git directory to the other projects worked as desired, however the .git directory is very large and becomes out of date after a commit. So I'm wondering if there is a better way to do this.
Upvotes: 0
Views: 315
Reputation: 15622
as simple as this:
git init .
git remote add origin [URI TO THE EXISTING REMOTE]
git fetch # transfer remote history to your PC
git checkout master # checkout files of master branch
Upvotes: 4