# Deploying App On Heroku with Git
Prerequisites: Install Git and the Heroku CLI
```
git init and make a commit
//Be sure to initialize the Git repository in your app’s root directory. If your app is in a subdirectory of your repository, it won’t run when it is pushed to Heroku.
```
Creating a Heroku remote
creates a new empty application on Heroku
```
heroku create
Creating app... done, ⬢ thawing-inlet-61413
https://thawing-inlet-61413.herokuapp.com/ | https://git.heroku.com/thawing-inlet-61413.git
```
use the git remote command to confirm that a remote named heroku has been set for your app:
```
git remote -v
heroku https://git.heroku.com/thawing-inlet-61413.git (fetch)
heroku https://git.heroku.com/thawing-inlet-61413.git (push)
```
For an existing Heroku app
```
heroku git:remote -a thawing-inlet-61413
set git remote heroku to https://git.heroku.com/thawing-inlet-61413.git
```
Renaming remotes
```
git remote rename heroku heroku-staging
```
### Deploying code
```
git push heroku main
//Note that Heroku only deploys code that you push to master or main. Pushing code to another branch of the heroku remote has no effect.
```
Deploying from a branch besides main
If you want to deploy code to Heroku from a non-main branch of your local repository (for example, testbranch), use the following syntax to ensure it is pushed to the remote’s main branch:
```
git push heroku testbranch:main
```
### Detaching from the build process
After you initiate a Heroku deploy with git push, you can detach from the resulting build process by pressing Ctrl + C. This does not cancel the build or the deploy. The build will continue in the background and will create a new release as soon as it completes.
### check log
```
// check log
heroku logs --tail
```
{"metaMigratedAt":"2023-06-16T03:25:55.736Z","metaMigratedFrom":"Content","title":"Deploying App On Heroku with Git","breaks":true,"contributors":"[{\"id\":\"80b3d720-6f93-4f74-81f3-c40e0826dd23\",\"add\":1782,\"del\":1}]"}