DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Developer Git Commit Hygiene
  • Understanding Git
  • Adding a Selenium-Maven Project From Eclipse to GitHub Repository
  • Git Tags vs AWS Tags: A Tag-Tastic Showdown!

Trending

  • Immutable Secrets Management: A Zero-Trust Approach to Sensitive Data in Containers
  • MySQL to PostgreSQL Database Migration: A Practical Case Study
  • Agentic AI for Automated Application Security and Vulnerability Management
  • How to Convert XLS to XLSX in Java
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Tutorial: Git with Eclipse

Tutorial: Git with Eclipse

If you aren't currently using a version control system or are exploring one, check out how to use Git with Eclipse using the EGit plugin.

By 
Erich Styger user avatar
Erich Styger
·
Oct. 05, 18 · Tutorial
Likes (10)
Comment
Save
Tweet
Share
97.2K Views

Join the DZone community and get the full member experience.

Join For Free


EGit with Eclipse

EGit with Eclipse

VCS In a Nutshell

In a nutshell, a VCS is a database or a system which allows me to store and retrieve files. It keeps a history and I can go back in time to retrieve an earlier state or compare different states. It "versions" items or files in a kind of database. In most cases, such a database is used by multiple users or developers, and with this, the system is able to "merge" changes of different developers; it keeps an audit track and backup of all the changes. Not using a VCS for any medium or larger scale project especially with multiple developers collaborating sounds like suicide to me. If you never have used a version control system, you probably want to start using one. I have used different VCSs (CVS, SVN, Git), and while I still keep projects for historical reasons in CVS and SVN, I’m using Git for all my new stuff.

If a VCS or Git is new to you, I recommend you have a look at this tutorial video: https://git-scm.com/video/what-is-version-control

Git – Quick Start

The Git project has been started by the famous Linus Torvalds. It is a modern and distributed version control system. To install Git, follow the links and tutorial.

With Git there are several basic actions:

  • add: adding files to the list of changes
  • commit: enter the change into the (local) repository
  • push: transfer the changes in the local repository to the remote one
  • pull: get the changes from the remote repository

By default, there is always a local repository. A remote repository is needed to share something, e.g. on GitHub.

In the Git Bash shell, configure first your username and default email address:

git config --global user.name "John Doe"
git config --global user.email "john.doe@company.com"

Git configuration

Git configuration

That all that we need for configuration.

To create a new Git repository I use:

git init myGitRepo


which creates the repository with that name after the "init".

Next, I create a readme.txt in that folder created (I’m using nano below, you can use any text editor):

cd myGitRepo
nano readme.txt

To add that file to the repository I use:

git add readme.txt

and then commit it to the repository with:

git commit -m"initial version of readme"

added file to repository

Added file to the repository

Instead of doing things on the command line, you are free to use graphical clients.

EGit Client for Eclipse

I’m always having a GUI client installed beside of the command line version and the Eclipse plugin. Each client has its pros and cons, and I’m using SourceTree which is free-of-charge. My model is:

  1. Using a GUI client like SourceTree for normal working with Git
  2. Using the command line version for more advanced things or for automation
  3. Using the Eclipse plugin for working with Eclipse projects

My preference for an Eclipse plugin is "EGit," for which I wrote an article how to install into CodeWarrior. Many Eclipse distributions already come with a Git client pre-installed, and the NXP MCUXpresso IDE comes with EGit, too.

Otherwise, use (or update) from the following Eclipse Update site (Help > Install New Software):

http://download.eclipse.org/egit/updates

Going forward, I will show how to use Eclipse (NXP MCUXpresso IDE 10.2) with EGit.

Git Perspective and Repository Setup in Eclipse

In Eclipse I switch to the Git perspective:

Open Git Perspective

Open Git Perspective

From the Git perspective, I can add an existing repository (e.g. the one I have created above with the shell):

Add existing repository

Add existing repository

Then browse to the repository folder and add it:

Adding existing repo

Adding existing repo

Instead of using the shell, I can use it to create a new repository, too:

Create new repository

Create a new repository

Then it asks me for the repository folder name:

new eclipse git repository

New Eclipse Git repository

and it adds it to the available repositories:

List of repos

List of repos

Or I can clone from an existing repository, e.g. from GitHub. For this I use "clone":

Clone a Repository

Clone a Repository

For example, I can clone and use the McuOnEclipse repository on GitHub:

https://github.com/ErichStyger/mcuoneclipse.git

You won’t have access rights to push to that repository on GitHub. If you want to make changes to a GitHub repository, clone it on GitHub to your own list of repository and use your repository URL.

Cloning McuOnEclipse

Cloning McuOnEclipse

Press next and select the desired branch (if any).

Select branch

Select branch

Then specify the (new/empty) directory name where to clone the repository:

Local Destination

Local Destination

Press Finish and it will download repository content which might take a while depending on the data in the repository.

Adding Projects to Repository

With the repository configured, I can add an existing project to a repository. Right-Click on the project and select Team > Share Project…

Sharing Project

Sharing Project

Select the VCS to use:

Select VCS

Select VCS

Select the repository to use and press Finish:

Selected Repository

Selected Repository

Ignore File

Git uses the file .gitignore to filter (hide) files or folders which should not end up in the repository.

Git stores the list of files and folders to be ignored into a file named .gitignore. By default, the Project Explorer view hides all files starting with a dot. To show them, use the "Filters and Customization" menu:

Filters and Customization

Filters and Customization

And then uncheck the *.resources setting:

Filters

Filters

With this I can edit the .gitignore file inside Eclipse:

Default .gitignore file

Default .gitignore file

The file is processed from the top to the bottom, with # used to start a comment line.

As a general rule: ignore everything which is derived or generated as it would easily create conflicts in the repository.

For a list of things to be ignored for CodeWarrior and Processor Expert see here.

Update: It is recommended to ignore the .settings folder of the project (see discussions in the comments section of this article). The .settings folder contains XML files with local plugin settings and are specific to the user. So do not put that folder into the version control system.

For MCUXpresso IDE and SDK projects it is very simple: only the output folder with the generated make and object files needs to be ignored which is usually named "Debug" and/or "Release." As seen from the above .gitignore, Eclipse already added this to the list, so we are fine.

Commit

In the previous step I have added the project to the list of changes. But it is not yet stored in the repository. For this I need to do a commit. With the project added I have now many more actions available in the Team menu:

Extendd Team Menu

Extended Team Menu

With the "Commit…" menu item I get a Git Staging view:

Git Staging

Git Staging

The left upper area shows all the changes. I have to stage them into the lower left area using drag&drop or using the "+" and "++" icons in that toolbar and add a commit message:

Ready to commit

Ready to commit

Then I can commit (make the change in the local repository and push later) or do a commit with a push to the remote repository.

I prefer to make smaller commits and then push them later. With a local (not shared) repository a push is not needed/possible as the push is to the remote repository.

Push, Pull and Compare

The push action is available in the Team menu:

Push

Push

In the same menu, I find the pull actions (to get the changes from the repository).

To compare the changes, double-click on the file and it opens the Eclipse diff view:

Compare Changes

Compare Changes

Import from Git

Another cool thing is that I can import projects from Git into my workspace. I use the Import item from the File menu:

Import

Import

Then select import from Git:

Import Projects from Git

Import Projects from Git

Select the repository source:

Select Repository Source

Select Repository Source

If you have cloned the McuOnEclipse repository, you can select that one or any of your repositories:

Select git Repository

Select Git Repository

Then select the folder with the project(s) to import:

Select Project to Import

Select Project to Import

That way I can easily import projects from any repository.

As always with Eclipse, there are many ways to do one thing. Another way to import projects is from the Git Repositories view:

Importing Git Projects

Importing Git Projects

More Features

Be free to explore more of the EGit features in Eclipse. I recommend going through the Git perspective default views. For example, the History view:

Git History View

Git History View

Git History

Git History

Summary

Eclipse with the EGit plugin makes it easy to work with the Git version control system. It takes a bit practice if not familiar with version control systems, but things are easy to learn and the internet is full of more tutorials and videos. Keep learning

Happy Gitting!


Git Eclipse Repository (version control) Version control Commit (data management)

Published at DZone with permission of Erich Styger, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Developer Git Commit Hygiene
  • Understanding Git
  • Adding a Selenium-Maven Project From Eclipse to GitHub Repository
  • Git Tags vs AWS Tags: A Tag-Tastic Showdown!

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!