I have cloned sample project from Heroku:
git clone https://github.com/heroku/node-js-getting-started.git
cd node-js-getting-started
When I run git remote -v
I get:
Now I want to link my existing GitHub repository (i.e.: https://github.com/user/my-repo
) with the cloned project.
My main goal is, if I push anything to GitHub, I want the changes to be happened in both places, the Heroku repository as well as my repository (i.e: https://github.com/user/my-repo
).
CodePudding user response:
I have cloned sample project from Heroku
You have cloned a sample project from GitHub. You won't have permission to push to that repository, but if you did, you'd be pushing to GitHub, not to Heroku.
Now I want to link my existing GitHub repository (i.e.:
https://github.com/user/my-repo
) with the cloned project.
Assuming that repository is empty, simply change the URL your remote points to:
git remote set-url origin https://github.com/user/my-repo.git
Now your origin
remote points to your own repository.
My main goal is, if I push anything to GitHub, I want the changes to be happened in both places, the Heroku repository as well as my repository (i.e:
https://github.com/user/my-repo
).
Normally, you'd be able to enable GitHub integration and configure pushes to your GitHub main
branch to trigger a build on Heroku, but that feature is currently disabled while Heroku investigates a security breach.
Until that gets resolved I suggest you add a second remote:
- Install the Heroku CLI
- Log into Heroku with
heroku login
- Add a remote with
heroku git:remote -a YOUR_APP
Then verify that you can push to both remotes individually:
git push origin main
git push heroku main
You can continue to deploy that way, and I suggest you do.
But if you really want to, you can add your Heroku push URL to your origin
remote so git push origin main
actually pushes to GitHub and Heroku. Heroku outputs useful build information when you push to it and I'm not sure how well the two outputs will be kept separate if you do this.
CodePudding user response:
I run this commands:
heroku login
heroku git:remote -a doctors-portal
git push heroku main
I am getting these error in PowerShell:
To https://git.heroku.com/doctors-portal.git
! [rejected] main -> main (fetch first)
error: failed to push some refs to 'https://git.heroku.com/doctors-portal.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first 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.