Git:如何在现有仓库中设置远程 [英] Git: how to set remote in existing repo
问题描述
请教一个问题
我在 git 上有一个不同分支的项目:
I have a project on git with differents branches:
大师预开发....
我已经通过 FTP(不是通过 git pull 或 git clone)将我的项目文件安装在另一台服务器上,以创建开发环境.
I've installed my project files in another server by FTP (not by git pull or git clone) ir order to create a dev enviroment.
开发环境中项目的文件夹没有git repo.我可以在不执行 git pull 或 git clone 的情况下将此文件夹设置为现有 repo(dev 分支)吗?
The folder of the project in dev enviroment don't have a git repo. Can I set that this folder is a existing repo (dev branch) without do a git pull or git clone?
推荐答案
转到您的项目文件夹.使用您现有的存储库 URL 添加远程 origin
.
Go to your project folder. Add a remote origin
with your existing repository URL.
$ git init
$ git remote add origin <existing-repo-url>
$ git checkout -b dev # checkout a new branch 'dev'
在拉出 master
之前,您需要 stash(清理工作树并保存更改临时框)您的更改.Stash 更改和 Pull master
分支更改/提交.
You need to stash (clean working tree and save changes temporary box) your changes before pull the master
. Stash the changes and Pull master
branch changes/commits.
$ git add .
$ git stash save 'local changes'
$ git pull origin master # pull 'master' into 'dev' branch
现在,从存储中检索/弹出本地更改.
Now, retrieve/pop local changes from stash.
$ git stash apply # return the code that cleaned before
$ git commit -m 'message'
$ git push -u origin HEAD # push to remote 'dev' branch
一切正常后,清理存储(可选).
Once all is ok then, clean the stash (optional).
$ git stash drop
这篇关于Git:如何在现有仓库中设置远程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!