如何将同一本地Git仓库关联至两个不同的Heroku项目?
关联本地Git仓库到第二个Cedar-16栈的Heroku项目
没问题,这其实是Heroku Git远程管理里很常见的操作,我来一步步带你完成:
第一步:查看当前已关联的远程仓库
先确认本地Git仓库现在关联的Heroku远程情况,在终端里运行:git remote -v你会看到类似这样的输出(第一个项目的远程通常默认叫
heroku):heroku https://git.heroku.com/first-project-name.git (fetch) heroku https://git.heroku.com/first-project-name.git (push)第二步:添加第二个Cedar-16项目的远程仓库
你需要把第二个Heroku项目作为新的远程添加到本地仓库,推荐给它起一个辨识度高的别名(比如heroku-cedar),方便和第一个项目区分。运行命令:heroku git:remote -a your-second-cedar-project-name -r heroku-cedar把
your-second-cedar-project-name替换成你第二个Cedar-16项目的实际名称(可以通过heroku apps命令查看所有项目列表)。第三步:验证并部署(可选)
再次运行git remote -v,你会看到新添加的远程:heroku https://git.heroku.com/first-project-name.git (fetch) heroku https://git.heroku.com/first-project-name.git (push) heroku-cedar https://git.heroku.com/second-cedar-project-name.git (fetch) heroku-cedar https://git.heroku.com/second-cedar-project-name.git (push)之后要部署到Cedar-16项目时,就可以指定这个远程分支:
git push heroku-cedar main(如果你的主分支是
master,就替换成master)
如果你以后想把第二个项目设为默认的heroku远程,也可以用git remote rename命令把原来的heroku改成别的别名,再把新的远程重命名为heroku,但一般更推荐保留两个不同的远程别名,这样可以随时切换部署到不同项目。
内容的提问来源于stack exchange,提问作者Jay Jung
相关产品推荐
相关产品推荐

