Git versioning for your NetBeans projects

The NetBeans IDE provides support for the Git version control client. The IDE’s Git support allows you to perform versioning tasks directly from your project within the IDE.

For a sole developer

Initializing a Git Repository

To initialize a Git repository from existing files that are not in source control yet, you need to complete the following steps:

  1. In the Projects window, select an unversioned project and right-click the project name.
  2. In the context menu, choose Versioning > Initialize Git Repository (alternatively, in the main menu, choose Team > Git > Initialize).
  3. Specify the path to the repository you are going to store your versioned files in the Initialize a Git Repository dialog box or click Browse and browse for the directory required.
  4. Click OK.

A .git subfolder is created in the folder you specified in step 3 above (your NetBeans project folder by default), which is your Git repository where all the data of your project snapshots are stored.

After you initialized the Git repository, you either add files or directly commit them to the Git repository.

See the original article for more.

For multiple developers

Enable SSH in your hosting server

SSH is a way to create secure connection between your machine and your server. For using SSH, you have to have server running SSH service and you should be allowed to login using SSH.

Hostgator also provides SSH access but it’s disabled by default. You can’t connect your hostgator server using SSH until you get it enabled.

Hostgator doesn’t provide a direct way to enable SSH using panel. You’ll have to contact hostgator staff to enable SSH for you.

Just login to live chat and tell them that you want to enable SSH. Provide your last transaction ID and you are done. They will enable SSH for you.

Use SSH using PuTTY

If you have Linux system, you can directly login to your hostgator server using SSH command. If you have windows system then you need the PuTTY to login to hostgator server using SSH.

I recommend downloading the PuTTY windows installer. In my case, I initially downloaded putty.exe, but my firewall (zoneAlarm) kept blocking the connection. So I tried downloading the installer and it worked with no problems.

Now from your programs, open PuTTY.

In the window that appears.

Host Name (or IP address): enter your domain, eg. www.my-domain.com

Port: the default hostgator port is 2222

Saved session: enter a name and save your session so that you can easily reconnect.

Now press open.Once you enable SSH session, you will be asked for username and password. Just give your username and password and you will be logged in to the hostgator server.

If you have a reseller account, give your whmcs cpanel username and password.

These are the successfull lines that will pop out.

Last login: Mon Mar  5 16:52:27 2012 from blablabla.host.gr

-jailshell-3.2$

First, let’s create the directory where we are going to put are website repositories. Let’s call it repos.

mkdir repos

In order to see that this folder exists, open filezilla, go to your root folder and check that it was successfully created.

Navigate into repos and create a new repo for our website, let’s call it my_project.

cd repos
mkdir my_project

Navigate into the new folder and initialize the new repository

cd my_project
git init

It will return a message like this

Initialized empty Git repository in /home/my_domain/repos/my_project/.git/

Copy this path, you will need it for NetBeans.

You’ve now initialized the working directory–you may notice a new directory created, named “.git”.

You may also need to run these commands, not sure.

git config receive.denyCurrentBranch ignore

chmod +x /home/my_domain/repos/my_projects/.git/hooks/

NetBeans

Now it’s time to set up NetBeans.

Right click on your project > Versioning > Initialize Git Repository.

Select the path where you want to save your local repository, press okay and wait a second until the blue boxes appear left to your project nodes.

Now, right-click on your project > Git > remote > push.

Repository URL: enter something like this

ssh://my-domain.com:2222/home/my_domain/repos/my_project/.git/

Insert your username and password.

Press next and wait until the push is complete (take a look at the bottom right corner of NetBeans).

Cloning the remote repository

Now let’s say that I’m the other developer and want to get the project. I can do this (in my computer) by cloning the remote repository.

Open netbeans, press Team > Git > clone

In the Repository URL enter the remote address from before.

ssh://my-domain.com:2222/home/my_domain/repos/my_project/.git/

Add username and address too.

As parent set wamp/www

And then the desired folder name.

Branching and merging

The Purpose of Branching

Say you are working on a paper. You’ve gotten a first draft out, submitted for review. You then get a new batch of data, and you’re in the process of integrating it into the paper. Halfway in, however, the review committee calls you up and tells you that you need to change some of your section headings to conform to format specifications. What do you do?

Obviously you don’t want to send them your half-baked revisions with corrected headings. What you want to do is jump back to the version you sent out, change the headings on that version, and send off that copy, all the while keeping your recent work safely stored somewhere else.

This is the idea behind branching, and Git makes it easy to do.

Learning resources

  • A great tutorial on the Git version control system.
  • Common SSH Commands tutorial.

 

 

Post A Comment

Anti-Spam Quiz: