Git: how to set remote in existing repo

2019-05-14 21:09发布

One question please

I have a project on git with differents branches:

Master Pre Dev ....

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.

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?

1条回答
我命由我不由天
2楼-- · 2019-05-14 21:33

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'

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
查看更多
登录 后发表回答