How to setup Git on Anypoint Studio using the EGit Plugin

git
sandeep
Sandeep Deshmukh
Customer Success Engineer
25 mins
Introduction

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.

Install EGit Plugin in Anypoint Studio 7

Here are the steps involved in installing the EGit Eclipse Plugin in Anypoint Studio.

  1. 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)choose eclipse version
  2. In Studio, click the Help menu → select Install New Software
  3. In the 'Available Software' window, click on Add Button and add a new name and URL copied then Click on OK
  4. Select 'Git Integration for Eclipse', and continue the installationgit integration
  5. 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'

  6. 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

    git

Nice job! You have now Git installed on Anypoint Studio!

Initial Commit to the Git Repository

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. 

  1. To create a local repository, In the Package Explorer, right-click the name of your project → select Team → select Share Projectcommit
  2. 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.)commit git
  3. Click on ‘Create Repository button’ and then finishcreative repo
  4. 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.cse starter api
  5. 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 Commitcommit
  6. 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’. cssgit
  7. Add a commit message to the text box and click on the ‘Commit’ button. Your changes will be stored in the local git repository.commit
  8. 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.commit2
  9. 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 Upstreampush
  10. Login to Github.com and copy the remote repository HTTPS URL to clone in your clipboard.github
  11. Paste the URL of the empty repository created in Remote Git and push the changespaste url
  12. Select the Specification for Push from the Source ref and Destination ref and then Click on Finish.specify source
  13. 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'.CSE starter API git
  14. You have Successfully committed your changes to the remote repository in Git using the EGit plugin.
Cloning a remote repository in Anypoint Studio

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:

  1. To clone a remote repository, Go to Menu bar → Window → Perspective → Open Perspective → Other → Select Gitmule
  2. Or you can type the keyword 'Git' in the Quick Access text box on the toolbar. Select the option with 'Perspective Git'perspective git
  3. In Git Perspective, Click on the ‘Clone a Git repository’ option.clone a git
  4. In the Clone Git Repository window, Enter the location of the remote repository i.e. your HTTPS URL.sign up
  5. 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.check out master
  6. 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'.click finish
  7. After you click on Finish, you will see a Git Project created at your chosen location.working tree
  8. 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.file system
  9. 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.copy the project into the workspace
  10. 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.remote repo
  11. Follow one of the standard Git workflows to Add/Edit/Delete files in your project.
Pull and Push to remote repository in Anypoint Studio

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.

  1. 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 repositorypull repo
    OR you can open Git Perspective , Select the Project repository → Pull. You will see the new changes that are ready to Merged in your repositorygit perspective
  2. After pull operation, you can check package explorer the new files that are added to the local workspace in your studiopull
  3. 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.sync
  4. 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.
  5. 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’. synchronize workspace
  6. 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.synchonize workspace
Conclusion

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.

Try Anypoint Platform for free

Start free trial

Already have an account? Sign in.

Related tutorials