Thursday, October 25, 2012

How to get a Grails Project into Git

Lets say you have a grails project that you want to share with your team/world using the Git version control. Here are the steps that may help you get there.

Please take a backup of your existing code before you try any of these steps out. I am not responsible for any loss to your work.

Before you start performing these steps, please make sure you have Git installed on your machine.

Test for Git Installation

1. Open command prompt and type
> git

If you do not see an output like the following line, you may not have Git installed

usage: git [--version] [--exec-path[=]] [--html-path]

To install Git on your local machine please see the instructions here.

Open an Account at BitBucket or GitHub

Open an account and create your repository called "mygrailsproject" in BitBucket, GitHub or a similar service.

Using the Git Repository

1.    Go to the root folder for Grails project
> c:\code\mygrailsproject

2.    Make the .gitignore file for Grails project
> grails integrate-with --git

3.    Create an empty git repository at the project root
> git init

4.    Optional: If you are using the STS (Eclipse IDE) please add this line to the created .gitignore /target-eclipse/

5.    Add the gitignore file to the repository
> git add .gitignore

6.    Commit the .gitignore as the first commit
> git commit -m "Added the gitignore file"

7.    Now see the status of the local repository
> git status

8.    Do a trial run to see that everything you are going to add to the repository is correct
> git add -n .

9.    If everything looks good perform the real git add
> git add .

10.    Now commit the code locally
> git commit -m "First version of the Grails software added"

11.    Add the Git origin (you should have created your repository in BitBucket, GitHub or a similar service by now)
> git remote add origin ssh://git@bitbucket.org/youraccount/mygrailsproject.git
or
> git remote add origin https://accountname@bitbucket.org/accountname/mygrailsproject.git

12.    Push the master to origin
> git push -u origin master



2 comments:

Unknown said...

Your steps worked great! The /target-eclipse/ directory gets added automatically to the .gitignore file now with Grails 2.4.2

Thanks for posting this

Unknown said...

Your steps worked great! The /target-eclipse/ directory gets added automatically to the .gitignore file now with Grails 2.4.2

Thanks for posting this


(c) Jyotirmaya Nanda 2012