| ... | ... | @@ -39,3 +39,104 @@ Ensure that HTTPS is selected and copy the URL (see below). |
|
|
|
<p align="center">
|
|
|
|
<img src="./images/gitlab-clone.png" alt="Copy the URL near the center of the page."/>
|
|
|
|
</p>
|
|
|
|
|
|
|
|
In Git Bash or a terminal (**not command prompt/Powershell**) type
|
|
|
|
```
|
|
|
|
git clone
|
|
|
|
```
|
|
|
|
and paste the URL you copied at the end (be sure to leave a space between `clone` and the URL).
|
|
|
|
Once you pasted the URL, press enter.
|
|
|
|
This will create a local copy of the repository on your machine.
|
|
|
|
If you run `ls`, you will see a new directory in the current folder.
|
|
|
|
|
|
|
|
In both labs, the first exercise is to create a "Hello World" program.
|
|
|
|
If you are in CPSC 150L and are using BlueJ, skip to [the BlueJ and Git tutorial](#bluej), complete that, and then return here.
|
|
|
|
If you are in CPSC 250L, skip to [the Eclipse and Git tutorial](#eclipse), complete that, and then return here.
|
|
|
|
|
|
|
|
## The Lab Workflow
|
|
|
|
|
|
|
|
In jEdit or BlueJ (CPSC 150L) or Eclipse (CPSC 250L), create your `HelloWorld.java` file.
|
|
|
|
Now return to your terminal and, in the project directory, run
|
|
|
|
```
|
|
|
|
git add .
|
|
|
|
```
|
|
|
|
This command tells Git to *track* all of the files and changes you have made thus far.
|
|
|
|
Now run
|
|
|
|
```
|
|
|
|
git commit -m "Created HelloWorld.java"
|
|
|
|
```
|
|
|
|
This command makes Git *log* all of the changes you have made and gives you a checkpoint to which you can return, much like a save in a video game.
|
|
|
|
To test this, make some changes in *HelloWorld.java* and save it.
|
|
|
|
Run
|
|
|
|
```
|
|
|
|
git status
|
|
|
|
```
|
|
|
|
This will tell you what has changed since your last commit.
|
|
|
|
It should tell you that `HelloWorld.java` was changed.
|
|
|
|
Now run
|
|
|
|
```
|
|
|
|
`git reset --hard`
|
|
|
|
```
|
|
|
|
and then check
|
|
|
|
```
|
|
|
|
`git status`
|
|
|
|
```
|
|
|
|
It says that no changes have been made, so check your `HelloWorld.java` file.
|
|
|
|
It should be at the state it was when you did your initial commit.
|
|
|
|
So far, we have only used Git to clone and log our changes, so lets *push* our changes to Gitlab.
|
|
|
|
To do so, run
|
|
|
|
```
|
|
|
|
git push origin master
|
|
|
|
```
|
|
|
|
In this command, Git will push all commits that you have made thus far to Gitlab
|
|
|
|
(when you clone a repository, the Git server from which you cloned it is named `origin`).
|
|
|
|
Now all of your commits are backed up to the Git server.
|
|
|
|
|
|
|
|
For this exercise, run `git add .`, `git commit -m "message"`, `git push origin master` each time you add a line to `HelloWorld.java`
|
|
|
|
in order to get a hang of the workflow (for example, when you declare the class, the `main` method, and when you finish).
|
|
|
|
|
|
|
|
**You should commit and push at regular intervals (like whenever you get a new jUnit test to pass, every 10 minutes, or at the end of class).**
|
|
|
|
|
|
|
|
Once we pushed our changes, the current versions of the files were uploaded to Gitlab.
|
|
|
|
This means that if we want to work on the project on a different machine, we just have to set up Git on the new machine.
|
|
|
|
We then clone the repository, and continue exactly where we left off.
|
|
|
|
Once we are done working on that machine, we push our changes back to Gitlab.
|
|
|
|
|
|
|
|
If you do work on another machine and decide to switch back to a machine you have used before, make sure that you push all your changes from your current machine.
|
|
|
|
After logging on to your old machine, run `git pull`.
|
|
|
|
This command will grab your new commits from the server and update your repository.
|
|
|
|
|
|
|
|
## IDE Specific Instructions
|
|
|
|
|
|
|
|
### BlueJ
|
|
|
|
|
|
|
|
For CPSC 150L students, open BlueJ.
|
|
|
|
|
|
|
|
After cloning, click BlueJ's "Project" menu and then click "Open Non BlueJ".
|
|
|
|
In the dialog that pops up, select the repository that you just cloned.
|
|
|
|
From here on continue with [the usage section](#the-lab-workflow) using Git from a terminal or Git Bash.
|
|
|
|
|
|
|
|
### Eclipse
|
|
|
|
|
|
|
|
For CPSC 250L students, open Eclipse.
|
|
|
|
|
|
|
|
Now that we have cloned the repository, we will create an Eclipse project in the Git repository.
|
|
|
|
Open the new Java project wizard, and name your project.
|
|
|
|
Do not click next yet though!
|
|
|
|
Instead uncheck the "use default location" box and instead enter the location of the Git repository here.
|
|
|
|
By default this location is `C:\users\<user_name>\git\<repository_name>` or `~/git/<repository_name>` on Windows or Linux and Mac OS respectively (see the figure below).
|
|
|
|
Now you can click next.
|
|
|
|
If you need to add jUnit to your project, do so in this window then click finish.
|
|
|
|
If you look in the project files, you will see the lab manual in the root and all of the test classes in the `src` directory.
|
|
|
|
|
|
|
|
<p align="center">
|
|
|
|
<img src="./images/eclipse-new-proj.png" alt="Place the lab name in the project name box, uncheck use default location, and enter the repository directory in the location box."/>
|
|
|
|
</p>
|
|
|
|
|
|
|
|
We can continue with [the usage section](#the-lab-workflow) using Git from a terminal or Git Bash.
|
|
|
|
|
|
|
|
[Go back to the Git Setup Tutorial](./git-setup)
|
|
|
|
|
|
|
|
[Return to Tutorial index](./index)
|
|
|
|
|
|
|
|
[Return to Bash and Git index](../home) |