git - 如何将现有的 git repo 推送到新的(本地)位置?
问题描述
我一直在尝试在线搜索我的问题,但所有答案都与 github 相关。
我在我的电脑上的文件夹中有一个现有项目,我想将它推送到一个新位置以用作我传入协作者的服务器。远程 git 项目将位于我知道位置的网络驱动器上。所以没有 Github 或类似的。
我会说我需要克隆指令的逆向:我需要向上“克隆”到一个新位置。谢谢!
编辑:
我做了以下事情:
cd /path/to/new/location
git init --bare .git
cd /path/to/existing/repo
git remote add origin /path/to/new/location/myrepo/.git
git push origin --all
正如预期的那样,我确实启动并运行了新的“服务器”。
但我也想在那里看到我的文件。我知道这是由于--bare
选项。是否有替代方法可以在服务器上获取所有存储库,包括工作目录?虽然我不打算使用 github,但是当您将存储库上传到它时,您确实会在 Web 应用程序中看到这些文件。我想要同样的东西,只是在本地。
我知道我是一个新手,但如果你不能只用一个解释裸存储库和非裸存储库之间区别的链接来回答我,请。我已经阅读了很多,但我仍然没有找到解决问题的方法。
请像与 5 岁的孩子交谈一样解释解决方案:-) 谢谢
解决方案
首先将目录更改为您希望远程存储库所在的网络驱动器路径。然后在那里创建一个空的“裸”git repo(一个接受推/拉的):
git init --bare my_repo
Now change to the path to your existing repo, and add a remote repo:
git remote add origin <remote path_to_my_repo>
Now you can push/pull to that repo.
git push origin master
Note if you want this 'remote' repo to be accessed directly by several people, you may want to also look at the --shared
option to git init
推荐阅读
- api - 如何将带有动态表格的网页抓取到 Google 表格中
- c++ - Openssl C/C++ 以编程方式从模数和指数中获取 RSA 公钥
- reactjs - React Native axios api 调用 Shopify
- javascript - 另一个可折叠部分中的可折叠部分不会足够展开
- python - Xpath如何检查给定父节点是否存在子元素?
- bazel - 如何在 Bazel 的 WORKSPACE 中设置 ENV VAR
- elasticsearch - Elasticsearch 中的“exists”过滤器是否需要索引
- excel - 在 Google 表格中编写动态引用(如 Excel 中的“#”)
- python - 找不到tomcat用户python模块
- spring - Swagger-UI 正在重定向到端口 8080 并在实施 SSL @8443 后给出错误页面