【问题标题】:Heroku + Git: How do I push to my remote branch? origin/master is detachedHeroku + Git:我如何推送到我的远程分支? origin/master 已分离
【发布时间】:2017-04-16 22:31:38
【问题描述】:

我按照 heroku 的指示克隆了我的 repo:

Clone the repository

Use Git to clone indigo-oms's source code to your local machine.

$ heroku git:clone -a indigo-oms
$ cd indigo-oms
Deploy your changes

Make some changes to the code you just cloned and deploy them to Heroku using Git.

$ git add .
$ git commit -am "make it better"
$ git push heroku master

但是现在每当我尝试结帐 master 时,它都会将我发送到 heroku/master。我希望能够签出我的origin/master 并能够先推送到那个,然后签出heroku/master,将我的origin/master 更改合并到其中,然后推送。

当我尝试结帐 origin/master 时,它说它已分离

➜  indigo-oms git:(3f939ff) git co master
Switched to branch 'master'
Your branch is up-to-date with 'heroku/master'.
➜  indigo-oms git:(master) git checkout origin
error: pathspec 'origin' did not match any file(s) known to git.
➜  indigo-oms git:(master) git checkout origin/master
Note: checking out 'origin/master'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

HEAD is now at 3f939ff... no need for comfirmation
➜  indigo-oms git:(3f939ff)

这是我在运行git remote 时看到的:

➜  indigo-oms git:(3f939ff) git remote
heroku
origin

【问题讨论】:

    标签: git heroku


    【解决方案1】:

    我从未使用过Heroku,但我认为您不应该直接使用origin/master 分支,因为这是一个跟踪 分支,其目的只是保持同步在实际遥控器上添加master 分支。

    相反,您的工作流程应该如下所示:

    # create branch for origin's master
    git checkout origin/master
    git checkout -b o_master
    
    # create branch for heroku's master
    git checkout heroku/master
    git checkout -b h_master
    

    如果您收到这些分支已经存在的错误,则忽略并继续执行后续步骤。您可以像使用任何两个常规 Git 分支一样使用这两个分支 o_masterh_master。这包括做你的工作、合并、变基和推送。至于推送,如果您想将主分支上的工作推送回其原始存储库,您可以这样做:

    git push origin o_master
    

    【讨论】:

    • 对于第二个命令,它抱怨分支已经存在,但是当我执行git checkout master 时,它会将我发送到heroku/master
    • 那么听起来你的默认来源是heroku。但它不应该带你去heroku/master;这是一个跟踪分支。
    • @Edmund 我给了你另一个更新,希望它更清楚一点。
    • 嘿蒂姆,问题似乎是因为heroku 是我的默认遥控器。使用此答案更改它为我修复了它:stackoverflow.com/a/4847136/1555312。现在我可以做git push heroku master 或只是git push master(这是起源/主人)。感谢您的帮助!
    猜你喜欢
    • 2012-07-25
    • 2015-08-14
    • 2020-09-16
    • 2011-02-27
    • 2011-09-10
    • 2016-07-08
    • 2016-01-23
    • 1970-01-01
    • 2012-05-22
    相关资源
    最近更新 更多