5. Git Hints

5.1. Download a Remote Branch to Replace a Local Branch

Here we are working with 2 upstream remotes

  1. my remote call it <origin>

  2. the project remote call it <upstream>

Rename local branch dev as a backup branch dev_bckup

git co dev
git br -m dev_bckup

Find all remote branches and their upstream repositories, then fetch a specific remote branch from an upstream repository. Finally check out the upstream repository and create a local repository with that name. (Assumes you do not have an local repository named <dev>)

git br -r
# git fetch <remote_name> <branch_name>
git fetch upstream dev
# create a new branch dev from fetched branch
# git checkout -b <new_branch_name> <remote_name>/<remote_branch_name>
git co -b dev upstream/dev
# push dev to origin
# git push <remote_name> <branch_name>
git push origin dev

5.2. Delete a Local and Remote Branch

git br -d <local branch name>
git push <remote name> --delete <remote branch name>

** Delete the Following **

5.3. Use Git with Heroku CLI


Update Heroku, I believe it requires a restart after the update

heroku update

Create an app in Heroku

$ heroku create
Creating app... done, ⬢ sheltered-brook-17119
https://sheltered-brook-17119.herokuapp.com/ | https://git.heroku.com/sheltered-brook-17119.git

Add a remote to your local repository. Note that heroku only deploys code to the master or main branch

$ heroku git:remote -a sheltered-brook-17119
set git remote heroku to https://git.heroku.com/sheltered-brook-17119.git
# check the remote was created
$ git remote -v
heroku  https://git.heroku.com/sheltered-brook-17119.git (fetch)
heroku  https://git.heroku.com/sheltered-brook-17119.git (push)
# rename a remote if you wish
$ git remote rename heroku heroku-staging