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.
- Git. Open a command prompt and type
git --version
to see if you already have Git installed. If not, download and install Git. - Eclipse. Download and install Eclipse IDE for Java Developers from the Eclipse downloads page.
- Java Development Kit (JDK). Open a command prompt and type
java -version
to see if you have Java installed already. If not, download and install the JDK appropriate for your operating system.
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.
- Create a Github repository.
- In the right-side of the page, copy the HTTPS clone URL.
For example, the Github repo URL for my Java samples is https://github.com/tomjoht/eclipse-java.git.
- 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 typingmkdir projects
. Thencd
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.
- 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).
-
All the files download when you clone the repo.
-
Add the Java projects to the repository:
The .
adds all file types. (It’s not a typo there.)
- Commit the files:
If you just type git commit
you’ll be prompted to add a commit message in a text editor using VIM.
- Push the files to the repository:
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.
- Browse to the Github repository you want to pull. For example: https://github.com/tomjoht/eclipse-java.git
- On the right-side of the page, copy the HTTPS clone URL.
For example, my Github repo URL is https://github.com/tomjoht/eclipse-java.git.
cd
to a convenient directory, such as asusers/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 ashttps://github.com/tomjoht/eclipse-java.git
).
- All the files download when you clone the repo. To get updates to the repo at a later time, use the
pull
command:
Tip: To see a list of git commands, type git --help
.
Import the projects into Eclipse
- 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.
- Go to File > Import > General and select Existing Projects into Eclipse.
- Next to “Select root directory,” browse to the cloned repository on your computer where you downloaded all the files from Github. Then select Open.
- Select the Add projects to working set check box, and then select the working set you created.
- Click Finish.
About 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.