Category: git

Combining your own local git repository with Openshift for deploying

On Openshift you can deploy a multitude of applications. You do this by adding the code to a git repository and pushing the result to the Openshift servers. In some cases, when you are already developing the code and you don’t want to manually copy the changes to the openshift checkout it is cumbersome to keep this in sync.

Remote git url during creation

The simplest solution is to, during the creation of your application, specify a remote git url to store the app data in. If for some reason you do not want that (repository is not public for example), there is another way to fix this.

Local branch

In this solution, a branch on your local repository will be used to push the code to the master of the Openshift repository. This solution is based on a Stack Overflow post.

Application creation

First, create the Openshift application using the normal flow and checkout the git repository linked to this application. We do this, because we want the contents of the .openshift folder, this is used by Openshift for configuration of the Cartridge. We will later overwrite the data in this repo with our own local git repository.

Preparing the local branch

In your own git repository with the existing code, branch from the master (or any other branch you want to openshift code to be based on):

> git checkout -b openshift
> git remote add openshift <openshift-git-repo-url>

We have just created a local branch called openshift, and added a remote repository called openshift. We will be committing changes to the local branch and pushing them to the openshift repo.

Now copy the .openshift folder from the checkout done earlier and copy this to your local openshift branch. After this modify any configuration you may have to match the openshift application (database, log locations, etc.). Commit your changes.

Pushing to openshift repo

We will now push the local branch to the openshift repo. This is not as simple as executing a git push, because the local branch is called openshift, but on the remote repository we want to update the master branch.

> git push openshift HEAD:master -f

This command will overwrite the remote repo with all local changes, because of the the -f flag. The HEAD:master parameter will tell git to push the branch to the master of the remote repo.

For any subsequent commits there is no need to specify -f again, because the repositories are now from the same source.

Leave a Comment

Use git-svn for SVN repositories

Recently I came across the possibility to use git to access SVN repositories. Basically you use the command

git svn ...

to checkout a SVN repository. This is then stored locally on your hard drive and accessible as an ordinary git repository. Updating your local checkout is done by issuing

git svn rebase

committing the changes back to SVN is done easily by issuing a

git svn commit

command.

This solution looks a very nice solution for older code sources which are still using SVN. There are some ifs and buts of course, with one the biggest remarks that branching and merging from your git-svn checkout back to SVN is discouraged because of the very different nature in branching between git and svn.

Leave a Comment