简体   繁体   中英

Heroku: git push staging local-branch:master

We have local feature branches, a github origin branch and Heroku staging and production remote branches.

As local features become ready for review by a larger audience we'd like to push them to staging :

$ git push staging local-branch-name:master
Fetching repository, done.
To git@heroku.com:app-staging.git
 ! [rejected]        local-branch-name -> master (non-fast-forward)
error: failed to push some refs to 'git@heroku.com:app-staging.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and integrate the remote changes
hint: (e.g. 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

Part of me wants to --force the issue but git push -f to a remote is taboo. I could pull in the changes as the "hint" says but given that the branches we push into staging are often short lived and may have little to do with each other this seems like it would be unnecessary and confusing.

What is the proper procedure for sharing a staging server on Heroku?

You're essentially using git on your staging server as a deployment mechanism, not for version control. You already have your real remote on github, so I don't see the harm in force pushing to your staging server as long as you never pull changes from it .

Force pushing is typically a bad idea for two reasons.

  1. You can lose commits . If you force push to a remote that is ahead of your branch, those commits ahead of yours will be lost.

  2. You can mangle other developers' repositories. If you force push to a remote branch that another developer has already pulled, their branch will be out of sync with the remote and it could be difficult to recover.

However, in this case you are only pushing to the repository. You will never lose commits because the upstream will never be ahead of any particular branch. Also, it is never pulled by other developers. For those reasons, it is ok to force push in this case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM