Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Workflow for creating new Maven project in Eclipse and bringing it to Github

I want to create a new Maven project in Eclipse and push it to a new repository on github. I am a bit stuck on the right order of steps to achieve this.

  • To use a Maven archetype, I cannot use a directory with files in it. So I cannot create a Maven project in a git local repository. So using the archetype should probably come first.
  • I also need to create a repository in my github account. If I do this through the github desktop app, this already creates a local repository for me.
  • Now I have an Eclipse project and a local repository, up to now unrelated. How should I "relate" them?

I found a lot of information about cloning from github, but my github repository does not have a Maven project yet, so I cannot import in Eclipse. If I use command line instead and an empty directory, I cannot apply Maven archetypes any more because the directory is not empty.

I am confused. Can somebody de-confuse me?

like image 863
J Fabian Meier Avatar asked Dec 08 '25 09:12

J Fabian Meier


1 Answers

  • Create a new Maven project (however you want to create it). This, of course, will create a new directory in the file system with all the resources.
  • Create a repository in Github.
  • From the command line (located inside the project directory) do git init. This will create the local repository inside that directory.
  • Next, add a remote to your local repository: $ git remote add origin https://github.com/user/repo.git (optionally replace origin for the name your remote repository is going to be called, also replace user for your github username and repo for the name of your github repository name)
  • Add all files to be commited in the local repository.

For example

$ git add .

# Adds the file to your local repository and stages it for commit. To unstage a file, use 'git reset HEAD YOUR-FILE'.
  • Commit changes.

For example:

$ git commit -m "Add existing file"
# Commits the tracked changes and prepares them to be pushed to a remote repository. To remove this commit and modify the file, use 'git reset --soft HEAD~1' and commit and add the file again.
  • Push to remote.

Just be clear, taking the following structure as reference, What I propose is to have as git repositories any of the directories project1, project2, projectN, not the whole worspace (/roo_dir/workspace/ directory).

/roo_dir/workspace/
            - project1
            - project2
            - projectN

Additional readings:

  • Considerations for Git Repositories to be used in Eclipse
  • Should I store git repository in Home or Eclipse Workspace?
  • Is it better to keep Git repository inside or outside of Eclipse workspace?
like image 95
lealceldeiro Avatar answered Dec 09 '25 22:12

lealceldeiro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!