Pierre Rymiortz
Pierre Rymiortz

Reputation: 1127

How to push Eclipse project to Github

I'm new to Git and Github and I'm trying to figure out how to push to the root directory on Github from Eclipse (Windows).

I have created a Github project called MyProject. MyProject is an Android project with the usual Android directory structure:

From Eclipse I push my Android project called MyGame to MyProject. MyProject now becomes a sub-directory to MyGame, so that the readme file in MyProject isn't visible unless the user first clicks on MyProject on Github to drill down one level in the directory hierarchy.

How can I push MyGame so that its contents (src folder, res folder, readme) become visible at the root level in the Github project.

Update: I tried using command line:

git remote add origin [email protected]:username/reponame.git
git push origin master

This has the same result, on Github the directory hierarchy is:

How can I make it

?

Upvotes: 3

Views: 1932

Answers (1)

andyg0808
andyg0808

Reputation: 1403

I believe your problem may be that your git repo in Eclipse is in the parent folder of the project. What you need is for your git repo to be in the project folder.

Now, Eclipse seems to recommend that Git repos be set up in the parent folder of their projects. I am guessing that this is so that later related projects that may be needed can be easily added to the git repo. If you're not worried about that, and just want it to work as you described, see below.

Note that I'm running Ubuntu Linux, and so my Eclipse and desktop will probably look different from yours.

First we're going to find out if my guess as to the problem is correct:

  1. Open the "Git Repository Exploring" perspective in Eclipse.
  2. Look at the "Git Repositories" view. See if the path given for your repository is pointing to the folder containing your project. If it is, continue with the instructions below.

If your repo is in the folder above your project, then the problem shapes up like this: Git will recreate all the paths in your repo relative to the repository itself when you push it to GitHub. If it is in the folder above your project, then all the paths will include the folder containing your project. So, you'll need to move your repo into the folder containing your project. I'll describe the steps to achieve that below.

  1. To begin, you'll want to make sure you don't have any uncommitted changes, or any stashed changes (if you don't know what stashed changes are, don't worry about them).
  2. As a matter of caution, you may want to create a complete copy of your current code & repository at this point if it's at all important.
  3. Open Windows Explorer and navigate to the folder containing your git repo, per the path given in the "Git Repositories" view.
  4. At this point, you may want to close Eclipse, to avoid changes startling it (they shouldn't, but "you never can tell with bees!")
  5. If you can see a .git folder in Windows Explorer, then go on to the next step. If not, you'll need to show hidden files. http://windows.microsoft.com/en-US/windows7/show-hidden-files gives instructions for Win7.
  6. Now you should be able to see a .git folder. Copy this into your project folder.
  7. Start Eclipse (if you closed it) and open the "Git Repositories" view again.
  8. Click the button to add an existing local git repository. Choose the project folder.
  9. Go back to the normal Eclipse Java perspective. Right-click your project and choose Team > Disconnect to temporarily stop heeding the old repository.
  10. Right-click on the project again and choose Team > Share Project.... When prompted for a repository, check the box to use the one in the project/parent folder. In the view below, check the box of the one which is directly within the project folder (it will probably have one dot next to a folder.) Then click the Finish button.
  11. Now you'll probably have a lot of catching up to do. Git will believe that you have deleted every file in your project and replaced it with a file with one less layer of directory path. You'll need to commit all those changes to get a clean repo.
  12. Push the changes from step ten to GitHub. Check that it looks as you expect.

I hope this helps. Please comment if something's unclear or there's another issue. Please make sure to have a backup before you try this... I've not tested it entirely, and I don't want to cause any unneeded grief.

Upvotes: 8

Related Questions