Cloning a Repository
If a remote Git repository exists (for example, on NCSU GitHub), you can get a copy of the existing repository. Cloning a remote repository gives Git a full copy of nearly all data that the remote repository has. Every version of every file for the history of the remote repository is pulled to your local .git repository directory by default when you execute the
git clone command.
For this course, you will find the clone URL of a remote repository in NCSU GitHub.
You will have to authenticate each time you try to interact (clone, push, or pull) with your remote NCSU GitHub repository.
Best Practice: Using SSH Keys for Authentication
If you want, you can setup SSH Keys so that you do not have to authenticate each time you type the git clone, git push, or git pull commands. If you decide to use SSH, you will need to use the SSH clone URL.
Cloning in Git Bash
To clone a remote repository, open Git Bash, and browse to your
GitRepositories base directory. Execute the following command:
git clone [url]
where [url] is the clone URL for your NCSU GitHub repository.
The name of the created repository directory will be the name of your repository (for example:
csc216-001-GP1-01 if your NCSU GitHub repository is
git clone in Practice
git clone command creates a new project workspace directory, initializes a .git directory inside it, pulls down all data from the remote repository, and checks out a working copy of the latest version of the files in the remote repository.
Your directory hierarchy should now look like:
GitRepositories [a directory that contains one or more of your Git repositories] -> <repository-name> [a single Git repository] -> .git [may be a hidden folder, depending on your operating system]
Now, open Eclipse to your chosen workspace location for your course-related assignments. Eclipse will show that your workspace is empty. You will need to tell Eclipse where your local git repository is:
- On the Eclipse menu bar, open: Window -> Show View -> Other…
- In the Show View window, expand the Git folder.
- Click Git Repositories, then click OK.
The Git Repositories window should now appear.
- Select Add an existing local Git repository
- Browse to the location of the repository you cloned. (in the example above: GitRepositories/csc216-[section]-[project]-[repo-number])
- Click OK, then click Finish to close the window.
- The local csc216-[section]-[project]-[repo-number] repository should now be displayed in your Git Repositories window in Eclipse.
Cloning in EGit
To clone a remote repository:
- Open Eclipse.
- Select Window > Show View > Other.
- Browse to select Git > Git Repositories.
- In the Git Repositories view, click Clone a Git Repository. That opens the Clone Git Repository wizard. You will be cloning remote repositories on NCSU GitHub to your local computer. You would also use this option if you were using a new or different computer that has not yet been connected to your remote repository.
- On the clone wizard’s Source Git Repository page, enter remote repository information as follows (if you copy your repository URI from NCSU GitHub and paste into the URL textbox, the other fields should be automatically filled-in for you): * URI: The URI of your NCSU GitHub repository. * Host: github.ncsu.edu * Repository Path: The suffix of the URI that follows the host (after the github.ncsu.edu) * Connection Protocol (select only one): Select HTTPS if you do not have an SSH key. Select SSH if you do have an SSH key. But first, follow the instructions in Preparing to clone under SSH. * Port: Leave this field blank. * Authentication under HTTPS: User: Your unity id Password: Your unity password * Authentication under SSH: User: git Password: Leave this blank
- Click Next to continue to the next page.
- You may see a caution page saying Source Git repository is empty if you have not committed any files to the repository. Click Next to continue to the Local Destination page.
- On the Local Destination Page, click Browse to select a directory on your computer for your local repository.
Reminder: Default EGit Repository Location
Unless you change the default directory location, EGit will save all repositories in the
- Click Finish. Your Git Repository view shows the repository that you just cloned.