Git is a free and open-source distributed version control system that is designed to protect your data between versions, and enable developers to share changes to their code cross-organizationally. Git and Anypoint Studio combined is powerful when you are working on a team where you will need to track changes made to integrations developed in Anypoint Studio. In this tutorial, learn how to set up the EGit Plugin which allows you to commit, clone, pull and push to repositories directly from inside the Anypoint Studio IDE.
The first step is to Sign up for Anypoint Platform for free. Click the button below to create a free account.
Here are the steps involved in installing the EGit Eclipse Plugin in Anypoint Studio.
- Go to Eclipse Release page, and copy the "p2 repository URL" for the Eclipse version you are using (or select the closest version to what you have installed)
- In Studio, click the Help menu → select Install New Software
- In the 'Available Software' window, click on Add Button and add a new name and URL copied then Click on OK
- Select 'Git Integration for Eclipse', and continue the installation
After the installation is complete you will need to restart the studio to apply the changes. The installation may take a few minutes, please observe the progress bar at the bottom right. When complete, click on 'Restart Now'
After the Studio restart, you can navigate to the Git perspective using the Quick Search option. Another way to open the Git Perspective is from the Menu Bar, Window → Perspective → Open Perspective → Other → select Git
Nice job! You have now Git installed on Anypoint Studio!
Initial Commit to Local and remote repository: Development of Mule Application in a team with multiple developers. You will need to create a repository in a shared location on Git to check in your studio code so other developers can collaborate.
- To create a local repository, In the Package Explorer, right-click the name of your project → select Team → select Share Project
- In the Configure Git repository window, Select the checkbox for ‘Use or Create a repository in parent folder of project’. (Note: Using this method you will make sure that the .git folder is created in your project root and not your parent folder.)
- Click on ‘Create Repository button’ and then finish
- In the Anypoint Studio package explorer, you can see the arrow mark and questions mark symbols for your studio files. This icon indicates that you have created a Git repository for your project on your local drive, but you have not yet registered it and are not yet tracking changes to the project.
- Now you need to register the local repository and track changes. To do this go to your package explorer, right click to the name of your project → select Team → select Commit
- Once you have clicked on the ‘Commit’ button. You will see the ‘ Git Staging’ tab opened up. Select all the files that you want to check-in in Git then right-click on the selected files and click on ‘Add to index’.
- Add a commit message to the text box and click on the ‘Commit’ button. Your changes will be stored in the local git repository.
- In the package explorer, you can now notice that you have a yellow barrel icon which indicates that the changes have been committed to your local git repo. Also, there is no more arrow icon next to the project name.
- Next you want to commit to your remote git repository. In the Package Explorer, right-click the name of your project navigate to Team → select remote --> Push to Upstream
- Login to Github.com and copy the remote repository HTTPS URL to clone in your clipboard.
- Paste the URL of the empty repository created in Remote Git and push the changes
- Select the Specification for Push from the Source ref and Destination ref and then Click on Finish.
- After the changes are committed to the remote repository you will see a window which will indicate that the changes are pushed successfully which is similar to the window below. Click on 'OK'.
- You have Successfully committed your changes to the remote repository in Git using the EGit plugin.
When working in a team of developers it is very important to agree on a common workflow. Take into consideration factors such as the project you're working on, deployment workflows and lastly teams personal preferences.
Cloning a project from a remote repository: After the initial commit, team members will start collaborating and adding code to the branch in development. To commit their changes to the remote repository they will first need to import a remote repository in their studio workspace. To import a repository from remote you will need to follow the steps below:
- To clone a remote repository, Go to Menu bar → Window → Perspective → Open Perspective → Other → Select Git
- Or you can type the keyword 'Git' in the Quick Access text box on the toolbar. Select the option with 'Perspective Git'
- In Git Perspective, Click on the ‘Clone a Git repository’ option.
- In the Clone Git Repository window, Enter the location of the remote repository i.e. your HTTPS URL.
- Click on Next and select the branch you want to work on. Here we have only master, so we will Check out the Master branch.
- Select the directory you want to store the repository. This will be the same location where you will make changes to the project in your local. You can choose the location of your workspace as well. Then Click 'Finish'.
- After you click on Finish, you will see a Git Project created at your chosen location.
- Next, switch to the Mule Design Perspective. Now you will need to import the project in your Package explorer so you can view project files and make new changes . In your workspace, Right Click in the empty package explorer section and click on Import → Anypoint Studio Project from File System.
- In the Mule Import window, select the location of the git repository you just cloned. Make sure that you uncheck the checkbox that says ‘ Copy the Project into workspace’ or you get an error that the project already exists.
- Click on Finish, you will now have a Mule Project which is synced with your remote repository. The yellow barrel next to the mule configuration file indicates that the project is in sync with a remote repository.
- Follow one of the standard Git workflows to Add/Edit/Delete files in your project.
As you collaborate with the team of developers to add/Edit files in your Mule Implementation. You will need to make sure that you update(Pull) your local repository of any changes that may have been done at the remote branch. This will ensure that you are not overwriting the changes of other developers and avoid the Conflict errors in your Anypoint Studio.
Pull changes in Anypoint Studio: As a best practice, developers are expected to commit unit tested code changes to the remote repository at the end of day. The following day, all the developers are expected to PULL the changes to their local repository so no file changes are overwritten by other developers.
- To pull changes from a remote repository, either open your package explorer → Right Click on the project → Team → Click Pull. Once you click on pull, you will see the new changes that are ready to be added to the repository
OR you can open Git Perspective , Select the Project repository → Pull. You will see the new changes that are ready to Merged in your repository
- After pull operation, you can check package explorer the new files that are added to the local workspace in your studio
- Now, once you have the new changes you can start making your changes to a file in the project. After modifying the files you will see an ‘>’ symbol for the files that are not in sync with the local git version.
- Once the changes are completed you can push the changes to the branch. If you are pushing the changes please follow the same instructions for push as mentioned earlier in this document.
- If you want to compare the new changes you are committing to the remote repository you can check this with the option ‘Synchronize with Workspace’.
- After you click ‘Synchronize workspace’ you will find a new perspective that will open up and it will show you the difference with the local and remote versions of the files that have differences.
Congratulations on completing the EGit and Anypoint Studio tutorial. This tutorial was focused on setting up Egit plugin with Anypoint Studio. Next time you refer to a git repo, make sure that you use EGit plugin to import the project in your Anypoint Studio. If you have any feedback on this article, please rate this tutorial below. To view our other quickstart guides and tutorials, visit the developer tutorial home page. Your feedback is much appreciated, thank you.