简体   繁体   中英

Git: linking local and remote repositories

I've been using Git for a website project.

However, for technical reasons, I have to remove the ".git" folder from the local folder so that an installation is able to proceed.

Afterwards, I would need to connect the local and remote repositories once again. Is this possible?

When you delete the .git folder, there will be nothing that you can do with relation to git commands. All the git commands won't work because it will no longer be a repository. So afterwards, if you tried something like git remote add origin http://... git would return something like not a git repository

The only option you would have to reconnect the repository is to clone the whole repository again.

If you have any changes that you would like to be implemented from your local machine, you would have to clone and then copy over the changed files manually.

This begs the question though: why would you delete the .git folder?

Technically, the .git folder is the repository; the directory it's in is the working copy . Erasing the .git folder will leave you with only a copy of a particular revision of the files; you will have to re-clone the repository from scratch to recover.

What you might like to do is separate the repository and the working copy. I do this for a website I track with Git, and it works well. You can accomplish this by using the --work--tree and --git-dir flags .

git --git-dir=~/myrepo.git --work-tree=/var/www/myrepo status

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM