11

I have created my first git repository and trying to put Spring Boot project.

In the initial git asked to configure ".gitignore" file but i was not sure what files must (supposed to) be in, so i ignored ?

In my first commit-push, i see several files APART FROM pom.xml and some of my .java files like,

.classpath
.gitignore
.project
.settings/org.eclipse.core.resources.prefs
.settings/org.eclipse.jdt.core.prefs
.settings/org.eclipse.m2e.core.prefs

And i am not sure why they are here ?
are they supposed to be there ?

How and where to create .gitignore file ?

Ojonugwa Jude Ochalifu
  • 26,627
  • 26
  • 120
  • 132
user252514
  • 307
  • 1
  • 3
  • 14

3 Answers3

22

Have a look into https://www.gitignore.io/ There you can create your recommended gitignore based on what you are using.

For Eclipse it says:

# Created by https://www.gitignore.io/api/eclipse

### Eclipse ###

.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
.recommenders

# External tool builders
.externalToolBuilders/

# Locally stored "Eclipse launch configurations"
*.launch

# PyDev specific (Python IDE for Eclipse)
*.pydevproject

# CDT-specific (C/C++ Development Tooling)
.cproject

# Java annotation processor (APT)
.factorypath

# PDT-specific (PHP Development Tools)
.buildpath

# sbteclipse plugin
.target

# Tern plugin
.tern-project

# TeXlipse plugin
.texlipse

# STS (Spring Tool Suite)
.springBeans

# Code Recommenders
.recommenders/

# Scala IDE specific (Scala & Java development for Eclipse)
.cache-main
.scala_dependencies
.worksheet

### Eclipse Patch ###
# Eclipse Core      
.project

# JDT-specific (Eclipse Java Development Tools)     
.classpath

# End of https://www.gitignore.io/api/eclipse

I had many discussions in teams whether to put IDE based files in GIT or not. Some like it, some say every developer knows how to configure their IDE for the project based on the pom.xml.

My opinion now also is, keep away all IDE files from VCS.

miwoe
  • 757
  • 1
  • 6
  • 17
6

The .classpath file, .project file, and .settings/ directory are used by the Eclipse IDE.

There are differing opinions about putting IDE-specific project files under source control. I prefer to exclude them (and let the IDE generate its project files from the pom, provided it has decent Maven integration - which eclipse does) because I've seen sharing them to cause more problems than it solves. Other people will probably tell you they should all be included, and I'll leave it to them to justify their reasons for that; point is, I don't believe there's a single definitive consensus on this.

The .gitignore file contains ignore rules. It specifically contains rules that are meant to be shared through the repository, so it should be included. (If you have ignore rules that you don't mean to share through the repository, there are other files where those would be defined; see the git ignore docs.)

Mark Adelsberger
  • 42,148
  • 4
  • 35
  • 52
1

When you use any IDE to develop an application, they usually generate an additional set of files where they save the project settings. It is considered bad practice to upload these settings to a version control tool such as git, svn, etc, because these configurations are specific to the development environment of each developer, in some cases it can prevent the project from opening properly in the IDE, because it tries to look for resources that are not on your PC, for this reason it is advisable not to upload these configurations.

How to avoid to upload the IDE's configurations?

Git gives us the .gitignore file, where we can set all files that we want to ignore. Just create the .gitignore file in your main project folder, for example ~/workspace/my-project/, open that file with any text editor (even within your IDE) and add the files to be ignored.

As @Michael says, you can generate a set of files to ignore in base of IDE that you are using, take a look at this link, for example for eclipse (click here to generate) copy and paste the configuration within your .gitignore file.

If you have already uploaded these configurations to your repository, you must delete them so that the new gitignore configuration takes effect, check out these links revert changes in git, remove files from git

JUAN CALVOPINA M
  • 3,695
  • 2
  • 21
  • 37