|
| 1 | +--- |
| 2 | +title: "Git Workshop - Hands-On" |
| 3 | +output: html_document |
| 4 | +--- |
| 5 | + |
| 6 | +```{r, message=FALSE, warning=FALSE, include=FALSE} |
| 7 | +library(tidyverse) |
| 8 | +library(DT) |
| 9 | +``` |
| 10 | + |
| 11 | +```{r loaddata, message=FALSE, warning=FALSE, include=FALSE} |
| 12 | +hubs <- read_csv("data/hubs.csv") |
| 13 | +``` |
| 14 | + |
| 15 | +### Generate SSH Keys |
| 16 | + |
| 17 | +This must be done on each workstation you use to *push*. |
| 18 | + |
| 19 | +- https://gitlab.oit.duke.edu/help/ssh/README |
| 20 | + |
| 21 | +This step was covered in the [Outline Section](outline.html#generate_ssh_keys_in_advance_of_the_workshop) |
| 22 | + |
| 23 | +## Make a Repository |
| 24 | +1. Duke's GitLab -- <a href="https://gitlab.oit.duke.edu" target="_blank">https://gitlab.oit.duke.edu</a> |
| 25 | +1. Duke Shibboleth Login |
| 26 | +1. New Project <br><figure></figure><br> |
| 27 | +1. Add a project name. Use the name *test-one* <br> <figure><figcaption>replace 'my-awesome-project' with 'test-one'</figcaption></figure><br> |
| 28 | + |
| 29 | +1. Create Project<br><figure></figure><br> |
| 30 | + |
| 31 | + - GitLab will present a new page. Notice the section below the *Command line instructions* header. That information can come in handy. For future repositories, you may want to make a note of those Git commands. We will not use those commands today so you can move on. <br> |
| 32 | + |
| 33 | +1. Make a README file <br><figure> |
| 34 | +<figcaption>Open in a new tab for each link: README, LICENSE, and .gitignore</figcaption></figure><br> |
| 35 | + |
| 36 | + 1. Make a top level heading with the word "README" |
| 37 | + |
| 38 | + - i.e. type: `# README` |
| 39 | + - See [Markdown](markdown.html) for more information on Markdown tagging |
| 40 | + 1. After a blank line type: `This is my first GitLab repository.` |
| 41 | + 1. Commit changes |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | +1. Make a license file (Open in a New Tab, click the LICENSE link) <br><figure> |
| 47 | +<figcaption>Appply a license format</figcaption></figure><br> |
| 48 | + |
| 49 | + - choose *MIT* license, or paste a [Creative Commons](https://creativecommons.org/share-your-work/) License into license.md |
| 50 | + - Commit changes |
| 51 | + |
| 52 | + |
| 53 | + |
| 54 | +1. Make a .gitignore file (Open in a New Tab, click the .gitignore link) |
| 55 | + |
| 56 | + 1. *Apply a .gitignore format* |
| 57 | + |
| 58 | + - choose *R* |
| 59 | + |
| 60 | + 1. Commit changes |
| 61 | + |
| 62 | +1. Congratulations. You've just created your first GitLab repository. Click *test-one* in the top-left of your GitLab repo screen. Now you'll see your repository -- including the three files you just created. |
| 63 | + |
| 64 | + |
| 65 | + |
| 66 | +## Clone |
| 67 | + |
| 68 | +**Using RStudio**, clone your repository. Cloning will pull down the whole repo to your local system -- including the three files you just created. |
| 69 | + |
| 70 | +### Bring the repo down locally via RStudio |
| 71 | + |
| 72 | +1. Copy GitLab repo URL to clipboard |
| 73 | + |
| 74 | + - The repo should be at a location like this. `https://gitlab.oit.duke.edu/<<your-NetID>>/test-one`, copy the *git* URL to the clipboard by clicking the icon <br><figure> |
| 75 | +<figcaption>Copy the repo URL</figcaption></figure><br> |
| 76 | + |
| 77 | +1. Launch RStudio and create a *New Project...* |
| 78 | + |
| 79 | + 1. From the RStudio menubar: *File > New Project...* > Version Control > Git <br><figure><figcaption>Paste the GitLab repo URL (from the step above) into the *Repository URL:* field in RStudio</figcaption></figure><br> |
| 80 | + 1. Create Project |
| 81 | + 1. You may be prompted with a message which asks if you about the "authenticity of host". I like to verify the IP number is correct; then the answer is `yes`.<br><figure></figure><br> |
| 82 | + |
| 83 | + |
| 84 | + |
| 85 | +## Push: Edit and Commit |
| 86 | + |
| 87 | +**Continue in RStudio**. This time you'll make local changes by editing your local repository. After saving the changes you'll *add* and *commit* the changes. Lastly, you will *push* your changes up to the remote repository. |
| 88 | + |
| 89 | +<br><figure></figure> |
| 90 | + |
| 91 | +### Edit |
| 92 | + |
| 93 | +1. In the Files Pane, Open the README.md file |
| 94 | +1. In the Editor Pane, modify your README with [Markdown](markdown.html) |
| 95 | + |
| 96 | + - Make a Sub-heading with the word "Purpose" |
| 97 | + |
| 98 | + - i.e. `## Purpose` |
| 99 | + |
| 100 | + - After a blank line type: `This is my first Git repository. I'm going to push this file to GitLab via RStudio. Hello World.` |
| 101 | +1. Save the changes to this file |
| 102 | + |
| 103 | + |
| 104 | +### Commit & Push |
| 105 | + |
| 106 | +1. In the Git pane: |
| 107 | + |
| 108 | + 1. Check each of the staged files |
| 109 | + 1. Click *commit* and provide a message: `this is my first edit of a README and supporting files` |
| 110 | + 1. Click the *commit* button to engage your commit process with the message, then close |
| 111 | + 1. Click the *Push* arrow, then close, then close the commit dialogue box |
| 112 | +<br><figure></figure><br> |
| 113 | + |
| 114 | +1. View your changes back at GitLab: `https://gitlab.oit.duke.edu/<<your-NetID>>/test-one` |
| 115 | + |
| 116 | + |
| 117 | + |
| 118 | +## Pull |
| 119 | + |
| 120 | +The next time you open your project in RStudio the first step you should take is to *Pull* from the GitLab repo. Then make your changes, then commit and push. If you forget to *Pull* you may have to resolve some conflicts. For best results, get into the habit of pulling before you make edits. |
| 121 | + |
| 122 | +<br><figure></figure> |
| 123 | + |
| 124 | +## Public or Private Repositories |
| 125 | + |
| 126 | +- `https://gitlab.oit.duke.edu/<<your-NetID>>/test-one` > Settings > Scroll to *Project Visibility* > right-hand drop-down list: Private | Public |
| 127 | +- Add a Description (Optional) |
| 128 | +- Add Tags (Optional) |
| 129 | + |
| 130 | + |
| 131 | + |
| 132 | +## Public Hubs v Duke's Hub |
| 133 | + |
| 134 | +```{r, echo=FALSE, message=FALSE, warning=FALSE} |
| 135 | +datatable(hubs, rownames = FALSE, options = list(dom = 't'), |
| 136 | + escape = FALSE) %>% |
| 137 | + formatStyle("Duke's GitLab", color = "silver", backgroundColor = "navy", fontWeight = "bold") %>% |
| 138 | + formatStyle("Public Hubs", backgroundColor = "lightblue") |
| 139 | +``` |
| 140 | + |
| 141 | + |
| 142 | + |
| 143 | + |
| 144 | + |
0 commit comments