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:
Click the green button and you will see the following page:
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
git rm file1.txt git commit -m "remove file1.txt"
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.
<pre><code> String foo = "bar"; </code></pre>