简体   繁体   中英

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?

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

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:

Try this

  • Create a blank project in git hub
  • create a maven project in local
  • clone the git repo
  • this will not have any file
  • copy the maven project
  • add the files to git and push

Finally, I did the following:

  1. I created a new Maven project with an archetype in the directory for github local repositories.
  2. I used the github app to create repository with the same name in the same directory.
  3. Then I published this repository to github.
  4. Now I imported the project from the github local repository to eclipse.

The workflow is generally the one suggested by @lealceldeiro, but without using the command line git.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM