Skip to main content

Section 12.8 Getting the Project Code: Cloning

Now that we understand that Git is our local version tracking tool and GitHub is where the ArrayList capstone project repository is hosted online, we face the next practical problem: How do we get a copy of that online project onto our own computer so we can work on it?

Subsection 12.8.1 Solution: Cloning the Repository

The process of downloading a complete copy of a Git repository from a remote host (like GitHub) to your local machine is called cloning. When you clone a repository:
  • You download not just the latest versions of the project files, but the entire history of changes (all the snapshots/commits) stored in the repository’s .git folder.
  • Git automatically creates a new folder on your computer containing all the project files and the hidden .git history database.
  • Git also sets up a connection back to the original online repository (often referred to as the origin), which is important for more advanced workflows like fetching updates or contributing changes (though we won’t focus on those here).
Essentially, cloning gives you your own independent, fully functional Git repository on your local machine, based on the state of the remote repository at the time you cloned it.

Subsection 12.8.2 Cloning the ArrayList Project using VSCode

Subsubsection 12.8.2.1 Prerequisite: Installing Git

Before you can clone, you need the actual Git software installed on your computer. Visual Studio Code uses your computer’s Git installation to perform Git operations.
  1. Check if Git is Installed: VSCode might tell you if Git is missing when you try to use a Git feature (often in the Source Control view). You can also check by opening your system’s terminal or command prompt and typing git --version. If it shows a version number, you’re likely set. If you get an error ("command not found" or similar), you need to install it.
  2. Download Git: Go to the official Git website: https://git-scm.com/downloads
  3. Install Git: Download the installer appropriate for your operating system (Windows, macOS, Linux) and run it. Follow the prompts in the installer – for most basic uses in this course, accepting the default settings is usually fine.
  4. Restart VSCode: After installing Git, it’s essential to close and reopen Visual Studio Code so that it recognizes the new installation.
Ensuring Git is installed is a necessary first step before proceeding with cloning within VSCode.

Subsubsection 12.8.2.2 Cloning Steps in VSCode

With Git installed, here are the steps to clone the `ArrayList` example repository using VSCode’s built-in features:
  1. Open VSCode: Start VSCode. It’s often easiest if you don’t have another project folder open when initiating a clone.
  2. Initiate Clone: You have two common ways:
    • Via Command Palette: Open the Command Palette (Ctrl+Shift+P on Windows/Linux, Cmd+Shift+P on macOS), type Git: Clone, and select the command.
    • Via Source Control View: Open the Source Control view from the Activity Bar (the icon with branching lines). If no repository is open, you should see a button labeled Clone Repository. Click it. (If a different project is open, you might need to use the Command Palette method).
  3. Provide Repository URL: A prompt will appear at the top asking for the repository URL. Paste the following exact URL for our project repository and press Enter:
    https://github.com/Charlotte-CCI-ICC/1213-arraylist-example.git
    Screenshot of the VS Code quick input prompt asking for a Git repository URL to clone.
    Figure 12.8.1. VSCode Prompt for Repository URL
  4. Choose Local Directory: Your computer’s file explorer will open, asking you where you want to save the cloned project folder. Navigate to the parent directory where you keep your course projects (e.g., your Documents, Desktop, or a dedicated course folder) and select that location (the button might say "Select Repository Location" or similar).
  5. Cloning and Opening: VSCode will download the repository from GitHub (you might see progress indicators). Once finished, it will likely show a notification in the bottom-right corner asking if you want to open the cloned repository. Click Open.
You should now have the 1213-arraylist-example project folder open in VSCode. Congratulations, you’ve cloned your first repository! This folder is your local copy, complete with its Git history.
Note 12.8.2. For More VSCode Git Info.
VSCode’s integration with Git is quite powerful. For more details beyond what we cover here, you can refer to the official documentation you reviewed: Introduction to Git in VS Code
Note 12.8.3. Alternative: Command Line Cloning.
As mentioned, Git is fundamentally a command-line tool. If you open your system’s terminal or Git Bash, navigate (cd) to where you want the project, you can run:
git clone https://github.com/Charlotte-CCI-ICC/1213-arraylist-example.git
This achieves the same result. You would then open the resulting folder in VSCode manually. We recommend using the VSCode interface for this course.
You have successfully obtained a local copy (a clone) of the project repository. However, by default, cloning usually checks out the repository’s main line of development, often called the main branch. For our project, the main branch contains the *completed* solution. To start the exercises, you need to switch to a specific branch containing the starter code. The next section explains what branches are and how to switch to the correct one.
You have attempted of activities on this page.