Import Java code examples using Git

From Knowledge Kitchen
Jump to navigation Jump to search


Overview

Readymade code examples in Java for this course are publicly available on GitHub, an online resource for sharing and collaborating on code.

While it is certainly possible to copy/paste code from these examples, there is a better way to download them and keep them up-to-date as new examples are added using a code versioning and sharing tool called Git. Note that if you are using Eclipse, there are separate instructions for downloading these Java examples into the Eclipse environment.

Assumptions

This document assumes you are running a UNIX-like command shell, such as Terminal on Mac or Git Bash on Windows, and you are familiar with basic UNIX commands.

Choose a directory in which to store the examples

Decide in which directory you would like to store the example files, and then make that your current working directory.

Fork the examples

Follow these instructions to make a copy of the example Java programs:

fork
  1. With a web browser, go to the examples repository on GitHub - https://github.com/bloombar/java-examples.
  2. Click the button that says "fork" to make a copy of these examples into your own GitHub account.
  3. You will automatically be taken to a web page showing your copy of these examples

Download your copy of the examples

Once you have made a "fork" of the Java examples by following the instructions above, run the following command on your own computer's command line to download all the examples for the first time:

git clone https://github.com/your_github_handle/java-examples.git

Replace "your_github_handle" in the command above with your own GitHub username.



What links here