Best way to export the Eclipse project to GitHub

advertisements

I need to export an Eclipse project to GitHub. I am using Eclipse-Mars with the eGit plugin. I have spent hours reading documentation, tutorials, and posts and see that there are basically two ways

  1. Create an Eclipse project and a local Git repository. Commit to local repository. Create a repository on GitHub. Push the Eclipse project to the repository on GitHub. When I try this, I get the error "rejected non-fast-forward". I have no idea why. I did create a .gitignore on GitHub when I created the repository - is that causing a problem?

  2. Create a repository on GitHub. In Eclipse, clone this repository and then add files. Commit to local repository, then push. This works, but I end up with a weird configuration on GitHub: reponame/myprojname/src when I would prefer the more normal reponame/src

Which method is the correct way to proceed? Why do I get the push error in the first method, and why the strange folder layout in the second?


You first need to pull the github code into you local machine.

=> git remote add origin

=> git pull origin master

will automatically fetch and merge the github repo with your local copy. You may need to resolve some conflicts that could be generated due to 3-way merge. After all this, you can use -

=> git push -u origin master

For the second Point, If you want src/ directory directly under reponame/ on github, then you should execute git clone after creating the project in eclipse and git clone should be executed inside the myprojectname/ directory.