0

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:

Screenshot showing a remote named "origin" pointing to GitHub

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).

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257

1 Answers1

0

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.

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • `heroku login` `heroku git:remote -a YOUR_APP` `git push heroku main` not working it gives error. – Shakhawat Hossain SHIHAB Apr 26 '22 at 14:30
  • [errorMessage] (https://i.ibb.co/NFmDjHQ/Capture.png) – Shakhawat Hossain SHIHAB Apr 26 '22 at 14:37
  • @ShakhawatHossainSHIHAB, "an error" isn't very helpful. Please [edit] your question, specify the command you are running, and include the complete error there. Or at the very least share it as text (not an image) in a comment. – ChrisGPT was on strike Apr 26 '22 at 14:37
  • [Please don't post screenshots of text](https://meta.stackoverflow.com/a/285557/354577). They can't be searched or copied, or even consumed by users of adaptive technologies like screen readers. Instead, paste the code as text directly into your question. If you select it and click the `{}` button or Ctrl+K the code block will be indented by four spaces, which will cause it to be rendered as code. – ChrisGPT was on strike Apr 26 '22 at 14:38