I have a Heroku project which I deploy using the Heroku CLI and I would like to transfer this project in a new repo on my GitHub account but I'm getting really confused about how these "remotes" work. I've only found people trying to do the opposite (from GitHub repo to Heroku app).
-
https://stackoverflow.com/questions/4658606/import-existing-source-code-to-github – phd May 23 '18 at 16:46
-
I wanted to mirror my repo from Heroku to Github personal so that it shows all commits etc also which I made in Heroku. https://docs.github.com/en/free-pro-team@latest/github/importing-your-projects-to-github/importing-a-git-repository-using-the-command-line in Github documentation was useful – Ravi R Oct 16 '20 at 10:14
1 Answers
A "remote" is pretty much just a name and a couple of URLs. The URLs are often the same. You can see your existing remotes by running git remote -v
in your project directory, e.g.
$ git remote -v
origin https://github.com/github/hub.git (fetch)
origin https://github.com/github/hub.git (push)
Here I have one remote, origin
, whose fetch
and push
URLs are the same.
If you run that command in your repository you will probably see at least a remote called heroku
pointing at the Git host that underlies Heroku (https://git.heroku.com/...
). This is what the Heroku CLI uses to deploy your application.
You need to add a new remote for your GitHub repository. If you haven't already, create a new repository on GitHub to contain your project. Do not initialize the project with a README, .gitignore
, or LICENSE
file¹. Make note of the URL that GitHub shows you after you've done this.
Now add the new repository as a remote with a name that makes sense:
git remote add <name> <github-url>
You can now push to the new remote using git push <name>
.
Regular GitHub access rules apply—you'll need to have an SSH key set up or provide your password. If you use 2FA and want to use HTTPS you'll need to set up a personal access code and use that instead of your password.
¹If you create these files you'll end up with a new commit on GitHub that doesn't exist in your local copy. In this case you won't be permitted to do a regular push.

- 127,765
- 105
- 273
- 257