Search results

Java: Share files with others using Git and Github

What’s the best way to share Java files with others, especially in a tutorial scenario? Here’s one way to share files using Github and Eclipse.

Prerequisites

If you’re sharing Java files, you need Eclipse and the JDK as well as Git. If you’re just sharing regular files, you only need Git.

Upload the Java projects to Github

Note: Only the person sharing the Java files needs to create the Github repository. Everyone else will clone and pull from this repo.

  1. Create a Github repository.
  2. In the right-side of the page, copy the HTTPS clone URL.

cloneurl

For example, the Github repo URL for my Java samples is https://github.com/tomjoht/eclipse-java.git.

  1. On your computer, open a command prompt and type pwd to see your present working directory. Then create a subdirectory called “projects” or something similar by typing mkdir projects. Then cd to this projects directory.

Tip: Although you can put your directory anywhere, it’s most convenient to use a subdirectory under the default directory your command prompt opens to.

  1. In the directory where you want to clone the repository, type the following, replacing {repo_url} with the actual URL of the Github repository (such as https://github.com/tomjoht/eclipse-java.git).
git clone {repo_url}
  1. All the files download when you clone the repo.

  2. Add the Java projects to the repository:

git add . 

The . adds all file types. (It’s not a typo there.)

  1. Commit the files:
git commit -m "your commit msg"

If you just type git commit you’ll be prompted to add a commit message in a text editor using VIM.

  1. Push the files to the repository:
git push

Download the Java projects from Github

If you’re sharing Java project files, this section is relevant. If you’re just sharing regular files, skip this section.

Participants who want to grab the files from the Github repo follow these steps. If you created this repository, you don’t need to follow these steps.

  1. Browse to the Github repository you want to pull. For example: https://github.com/tomjoht/eclipse-java.git
  2. On the right-side of the page, copy the HTTPS clone URL.

cloneurl

For example, my Github repo URL is https://github.com/tomjoht/eclipse-java.git.

  • cd to a convenient directory, such as as users/projects.* In the directory where you want to clone the repository, type the following, replacing {repo_url} with the actual URL of the Github repository (such as https://github.com/tomjoht/eclipse-java.git).
git clone {repo_url}
  • All the files download when you clone the repo. To get updates to the repo at a later time, use the pull command:
git pull

Tip: To see a list of git commands, type git --help.

Import the projects into Eclipse

  1. In Eclipse, go to File > New > Java Working Set and create a working set called “Java Tutorials” (or something appropriate). A working set allows you to filter the projects shown in Eclipse’s Project Explorer pane.
  2. Go to File > Import > General and select Existing Projects into Eclipse.
  3. Next to “Select root directory,” browse to the cloned repository on your computer where you downloaded all the files from Github. Then select Open.
  4. Select the Add projects to working set check box, and then select the working set you created.
  5. Click Finish.

About Tom Johnson

Tom Johnson

I'm an API technical writer based in the Seattle area. On this blog, I write about topics related to technical writing and communication — such as software documentation, API documentation, AI, information architecture, content strategy, writing processes, plain language, tech comm careers, and more. Check out my API documentation course if you're looking for more info about documenting APIs. Or see my posts on AI and AI course section for more on the latest in AI and tech comm.

If you're a technical writer and want to keep on top of the latest trends in the tech comm, be sure to subscribe to email updates below. You can also learn more about me or contact me. Finally, note that the opinions I express on my blog are my own points of view, not that of my employer.