Monday, October 1, 2012

Renaming an OpenShift application

The OpenShift service from Red Hat lets you easily start and build web applications with common languages and frameworks such as Node.js, Ruby, Python, PHP, Perl, and Java.

For example, creating a new Django application is an easy 3 step procedure:

Create a python-2.6 application
rhc app create -a django -t python-2.6

Add this upstream repo
cd django
git remote add upstream -m master git://github.com/openshift/django-example.git
git pull -s recursive -X theirs upstream master

Then push the repo to openshift
git push

So far so good.

Unfortunately, if you later decide to give your new application a more meaningful name you realize there is no command to do so directly. I've found this procedure quick and effective:

Create the new application with the correct name, using the -n option will not clone the new repo:
[giallu@novo django (master)]$ rhc-create-app -a newname -t python-2.6 -n

Note the git url it gives you in the output, then issue:
[giallu@novo django (master)]$ git remote set-url origin newurl

Push your repo to the new url
[giallu@novo django (master)]$ git push

Finally, remove the older repository:
[giallu@novo django (master)]$ rhc-ctl-app -a django -c destroy

Optionally, you can rename your top level directory to match the new application name.

2 comments:

  1. what does this command means :

    git remote set-url origin newurl


    can you explain it with example??

    ReplyDelete
    Replies
    1. Do you know about remotes? a remote is essentially the repository toward you will be pushing or pulling commits.

      When you first do a 'git checkout' it creates a remote named 'origin'

      In this case, we need to change the url of the origin to point to the new repo. That's exactly what the 'set-url' subcommand does.

      Delete