On this tutorial, I will try to describe, how easily we can use git operations from within the IDE with using git plugin for Netbeans. Also, I will like to mention that, git support for Netbeans IDE started since version 7.x . So, please make sure your ide is updated . I am using Netbeans IDE 7.3(beta) while, writing this tutorial. If you are very new with git, you should first get basic knowledge on GIT first. As this tutorial assumes you already know git more or less and now want to use the git plugin for Netbeans. As a short course, you can refer to my important git commands tutorial.
Installing The GIT Plugin For Netbeans:
Go To ‘Tools’->’Plugins’ menu on Netbeans. You should be able to see few tabs like ‘available plugins’, ‘installed plugins’, ‘Downloaded’ and so on. Click on he available plugins, select the ‘git’ plugin from the list and install. After installation , it will be shown on ‘installed’ tab as like the following picture:
Initialize/Clone New Repository:
After the plugin in being installed, its time to create a new repository or clone a remote repository. Please got to ‘Team’->’Git’ menu option and you should see these options there.
If you are initializing new git repository, you can do so on an existing project directory or on an empty new directory. Just map the path, and you are done.
To clone a remote repository, you should see a pop up window as follows where you will need to enter corresponding information:
After you click ‘Next’, it will connect to the remote repository and will show the branches on the repository, from which, you can select one or more branches. Then, on next screen, you will need to specify the place on your local PC where the clone operation will be held. Now, if you just click ‘finish’, it will start the cloning process and show the logs on Netbeans output window.
Operations We Can Perform With GIT Plugin For Netbeans:
Almost all available git operations can be performed through this plugin. If you right-click on your project and go to git option, you should see the available options you can use as like the image below:
Perform Local Commit Using GIT Plugin:
This plugin makes commuting files easy! Just after you have completed all your addition/changes of files, you can just right-click the project, select “git->commit” option. It will show up a new dialog as follows:
You can check which files are being committed and on which state(like ‘added’/’modified’/’deleted’ etc). So, basically you will be able to get rid of ‘git add’ type commands. After you added a proper comments and check all are ready, just click the ‘commit’ button, it will do the rest of the work and log will be shown on output window.
Branching And Merging:
Working with branches and merge operations are also very easy to handle with Netbeans git plugin. To create a branch, use the option ‘git->branch->create’ and you will see new dialogues as below:
From the first dialogue, you can enter your preferred branch name and if you want to select a specific revision, either from local or remote, you can do so from the second dialogue. Switching branch is similar, just need to select the preferred branch and revision(if needed) and click OK on switch branch dialogue.
For merging, you can select the ‘form’ branch with which your current branch will be merged. If any conflict occurs, you can resolve it from both graphical and textual editor as like the image below:
This same editor can be used to compare two version of a file. For such usage, you can use the ‘git->diff’ option.
Pull/Push/Fetch From/To Remote repository:
Working with remote are a lot painless than the basic command line tool. You won’t have to switch to bash agent, add ssh key or enter password again and again. You just do it first time. Especially, if you have cloned from a remote repository, it should already be saved and you won’t need to do anything again about this part. For pushing, you should just select the local branch which will be pushed to which remote branch(you can select more than one!) and it will take care of the rest and show the log on output window. However, I am missing a lot about the complete log report feature here than the command line tool as it shows only major logs not all like command line/terminal.
Please refer to Official Netbeans documentation on git plugin for more. Also, you can ask any specific questions about usage of this git plugin for netbeans on comments as well. Happy coding 🙂
hey, using netbeans, can we do a diff between local branches, or local and remote ? afaik and as i try, git->diff only do diff in local sources, head/index/working tree.
help appreciated. 🙂
Md. Ali Ahsan Rana says
If yes, it does the diff operation on local branch. If you need to do so with remote branch, why not you first take update from remote branch and do the diff with remote’s latest branch?