
In this tutorial, I will try to describe how easily we can use git operations from within the IDE by using the git plugin for Netbeans. Also, I would like to mention that git support for Netbeans IDE started in 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 to git, you should first acquire basic knowledge of GIT. 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 useful 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 the available plugins, select the ‘git’ plugin from the list and install it. After installation, it will be shown on the ‘installed’ tab as in the following picture:
Initialize/Clone New Repository:
After the plugin is installed, it’s time to create a new repository or clone a remote repository. Please go to the ‘Team’->’Git’ menu option, and you should see these options there.
If you are initializing a new git repository, you can do so in an existing project directory or 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 the corresponding information:
After you click ‘Next,’ it will connect to the remote repository and show the branches on the repository, from which you can select one or more branches. Then, on the 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 the 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 the 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 additions/changes of files, you can just right-click the project and select the “git->commit” option. It will show up a new dialogue as follows:
You can check which files are being committed and in which state(like ‘added’/’modified’/’deleted’, etc.). So, basically, you will be able to get rid of ‘git add’ type commands. After you add proper comments and check that everything is ready, just click the ‘commit’ button. It will do the rest of the work, and the log will be shown in the output window.
Branching And Merging:
Working with branches and merge operations are also very easy to handle with the 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. If you want to select a specific revision, either local or remote, you can do so from the second dialogue. Switching branches is similar; you just need to select the preferred branch and revision(if needed) and click OK on the switch branch dialogue.
To merge, 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 editors as like the image below:
This same editor can be used to compare two versions of a file. For such usage, you can use the ‘git->diff’ option.
Pull/Push/Fetch From/To Remote repository:
Working with a remote is a lot more painless than the basic command line tool. You won’t have to switch to a bash agent, add an SSH key or enter a password repeatedly. You just do it the 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 the output window. However, I am missing a lot more about the complete log report feature here than the command line tool, as it shows only major logs, not all, like the command line/terminal.
References:
Please refer to the official Netbeans documentation on the git plugin for more information. Also, you can ask any specific questions about the usage of this git plugin for Netbeans in the comments as well. Happy coding 🙂
Discover more from CODESAMPLEZ.COM
Subscribe to get the latest posts sent to your email.
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. 🙂
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?