Share an Eclipse Project to GitHub in 2 Steps?

If you have a project in your eclipse workspace and you want to share it on GitHub, how to do it? Very simple!

Assuming you already registered a GitHub account and you have already installed git on your computer, you can share your eclipse projects to GitHub in 2 easy steps.

Note: The following approach works for Mac, Linux, and Windows (assuming you have installed cygwin on your windows). If you use BigBucket instead of Github, it is exactly the same!

Step 1: Create a new repository on GitHub

The button is located on top-right corner:

share-eclipse-projects-to-github

Click the green button and you will see the following page:

github-create-a-repository

You can input only repository name, e.g., “face-collage-maker”, and leave others as default.

Step 2: Run the following command lines

On your computer, cd to your project directory in eclipse workspace, and then type the following command lines one by one.

$ git init

The “init” command initiates a new git repository in the project directory.

When are done, you need to register the new repository with a remote (where you’ll upload — push — your files to). In this case, the remote is Github. You’ll need to get the correct URL for your repository on GitHub.

Type in command line:

$ git remote add origin https://github.com/[username]/[reponame].git

In my case, it is [username] is “ryanlr” and [reponame] is “face-collage-maker”. So the URL is “git remote add origin https://github.com/ryanlr/face-collage-maker.git”

Now, add all files to your local commit:

$ git add .   # this adds all the files

Then make an initial commit:

$ git commit -a -m "Initial commit" 

This stages your files locally for commit, but they have NOT actually been pushed yet. You’ve created a commit in your local repository, but not in the remote one. To put it on the remote, do:

$ git push -u origin --all

Additional Commonly Used Command Lines

Remove files:

git rm file1.txt
git commit -m "remove file1.txt"

Commit Changes:

git add file
git commit -a

Then “git push” to push to repository.

If the repository on remote is not empty, you need to do “git pull origin master”, before pushing anything.

Useful Links

1. Generating SSH keys
2. Adding an existing project to GitHub using the command line

7 thoughts on “Share an Eclipse Project to GitHub in 2 Steps?”

  1. Just to add If the remote is created with readme.md and gitignore then before $ git push -u origin –all , you may need to pull so that you have the changes in local repository. with hints saying hint: Updates were rejected because the remote contains work that you do

    hint: not have locally. This is usually caused by another repository pushing

    hint: to the same ref. You may want to first integrate the remote changes

    hint: (e.g., ‘git pull …’) before pushing again.

  2. “git add file” or “git commit -a” to commit changes. Then “git push” to push to repository.

Leave a Comment