|
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | +## Get Organized |
| 5 | + |
| 6 | +Opening different terminals |
| 7 | +- terminal app on mac, use the `bash` command to use bash (zsh will be mostly the same; it's derivative, but to ensure exactly the same as mine use bash) |
| 8 | +- use gitbash on Windows |
| 9 | + |
| 10 | + |
| 11 | +We can move around and examine the computer's file structure using shell commands. |
| 12 | + |
| 13 | +`cd` is for change directory. We can use the relative path to get to where we |
| 14 | +want to go. We can see what files and folder are at our curent location with `ls` |
| 15 | +if we need a reference. |
| 16 | + |
| 17 | + |
| 18 | +```bash |
| 19 | +cd Documents/inclass/ |
| 20 | +``` |
| 21 | +We can use ls in the folder we get to. I chose to go to a place where I save |
| 22 | +content I use during my classes that I teach. |
| 23 | + |
| 24 | +```bash |
| 25 | +ls |
| 26 | +``` |
| 27 | +I already have a folder for the other class: |
| 28 | + |
| 29 | +```bash |
| 30 | +prog4ds |
| 31 | +``` |
| 32 | + |
| 33 | +I need a folder for this class, so I will make one with `mkdir` |
| 34 | + |
| 35 | +```bash |
| 36 | +mkdir systems |
| 37 | + |
| 38 | +``` |
| 39 | + |
| 40 | +To view where we are, we **p**rint **w**orking **d**irectory |
| 41 | + |
| 42 | +```bash |
| 43 | +pwd |
| 44 | +``` |
| 45 | + |
| 46 | +It prints out the *absolute* path, that begins with a `/` above, we used a relative |
| 47 | +path, from the home directory. |
| 48 | + |
| 49 | +```bash |
| 50 | +/Users/brownsarahm/Documents/inclass |
| 51 | + |
| 52 | +``` |
| 53 | + |
| 54 | +```{admonition} Checkin |
| 55 | +What is the absolute path of the home directory? |
| 56 | +``` |
| 57 | + |
| 58 | +Next I will go into the folder I just made |
| 59 | +```bash |
| 60 | +cd systems/ |
| 61 | + |
| 62 | +``` |
| 63 | + |
| 64 | +## Issues and Commits |
| 65 | + |
| 66 | +create a [test repo for today's class](https://classroom.github.com/a/U9WXbUBo) |
| 67 | + |
| 68 | + |
| 69 | +First we're going to see how issues and commits relate. |
| 70 | + |
| 71 | +Let's create the README on github and make a pull request with `closes #1` in the PR |
| 72 | +message. |
| 73 | + |
| 74 | + |
| 75 | + |
| 76 | +Notice what happened: |
| 77 | +- the file is added and the commit has the the message |
| 78 | +- the issue is closed |
| 79 | +- if we go look at the closed issues, we can see on the issue that it was linked |
| 80 | +- from the issue, we can see what the changes were that made are supposed to relate to this |
| 81 | +- we can still comment on an issue that is already closed. |
| 82 | + |
| 83 | + |
| 84 | +## Authenticating with GitHub and cloning a repo |
| 85 | + |
| 86 | +We have two choices to Download a repository: |
| 87 | +1. clone to maintain a link using git |
| 88 | +1. download zip to not have to use git, but have no link |
| 89 | + |
| 90 | + |
| 91 | + |
| 92 | +For a public repo, it won't matter, you can use any way to download it that you wuold like, but for a private repo, we need to be authenticated. |
| 93 | + |
| 94 | +Depending on how you have authenticated with GitHub, a different version of the URL will be highlighted. |
| 95 | + |
| 96 | +For today, if you have ssh keys already set up, use that. |
| 97 | + |
| 98 | + |
| 99 | +### Authenticating with GitHub |
| 100 | + |
| 101 | +There are many ways to authenticate securely with GitHub and other git clients. We're going to use *easier* ones for today, but we'll come back to the third, which is a bit more secure and is a more general type of authentication. |
| 102 | + |
| 103 | +1. GitHub CLI: enter the following and follow the prompts. |
| 104 | + |
| 105 | + ``` |
| 106 | + gh auth login |
| 107 | + ``` |
| 108 | +1. [personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token). This is a special one time password that you can use like a password, but it is limited in scope and will expire (as long as you choose settings well) |
| 109 | +1. ssh keys |
| 110 | +1. GitBash built in authentication |
| 111 | +
|
| 112 | +
|
| 113 | +
|
| 114 | +Or we can use use the GitHub CLI tool to authenticate. |
| 115 | +
|
| 116 | +On Mac with GitHub CLI: |
| 117 | +```bash |
| 118 | +gh auth login |
| 119 | +``` |
| 120 | + |
| 121 | +On Windows, Try the clone step and then follow the authentication instructions. |
| 122 | + |
| 123 | +On Mac, clone after you are all logged in. |
| 124 | + |
| 125 | +````{margin} |
| 126 | +```{warning} |
| 127 | +My repository, like yours, is private so copying these lines directly will not work. You will have to replace my GitHub username with your own. |
| 128 | +``` |
| 129 | +```` |
| 130 | + |
| 131 | +```bash |
| 132 | +git clone https://github.com/introcompsys/github-inclass-brownsarahm.git |
| 133 | +``` |
| 134 | + |
| 135 | +````{margin} |
| 136 | +git tells us exactly what happened: |
| 137 | +```` |
| 138 | + |
| 139 | +``` |
| 140 | +Cloning into 'github-inclass-brownsarahm'... |
| 141 | +remote: Enumerating objects: 9, done. |
| 142 | +remote: Counting objects: 100% (9/9), done. |
| 143 | +remote: Compressing objects: 100% (6/6), done. |
| 144 | +remote: Total 9 (delta 0), reused 4 (delta 0), pack-reused 0 |
| 145 | +Receiving objects: 100% (9/9), done. |
| 146 | +
|
| 147 | +``` |
| 148 | +We can also see that it created a new folder: |
| 149 | + |
| 150 | +```bash |
| 151 | +ls |
| 152 | +``` |
| 153 | + |
| 154 | + |
| 155 | +``` |
| 156 | +github-inclass-brownsarahm |
| 157 | +``` |
| 158 | + |
| 159 | +## What is in a repo? |
| 160 | + |
| 161 | +We can enter that folder |
| 162 | +```bash |
| 163 | +cd github-inclass-brownsarahm/ |
| 164 | +``` |
| 165 | + |
| 166 | +and see what is inside |
| 167 | +```bash |
| 168 | +ls |
| 169 | +``` |
| 170 | + |
| 171 | + |
| 172 | +``` |
| 173 | +README.md |
| 174 | +``` |
| 175 | +Notice that the `.github/workflows` that we see on GitHub is missing, |
| 176 | +that is because it is hidden. All file names that start with `.` are hidden. |
| 177 | + |
| 178 | +the `-a` option allows us to see them |
| 179 | +```bash |
| 180 | +ls -a |
| 181 | +``` |
| 182 | + |
| 183 | +We also see some special "files", `.` the current location and `..` up one directory |
| 184 | + |
| 185 | +``` |
| 186 | +. .. .git .github README.md |
| 187 | +``` |
| 188 | + |
| 189 | +## Relative paths |
| 190 | + |
| 191 | +We can see clearly where `..` goes by printing our our location before and |
| 192 | +after changing directory to `..` |
| 193 | + |
| 194 | +```bash |
| 195 | +pwd |
| 196 | +``` |
| 197 | + |
| 198 | + |
| 199 | +``` |
| 200 | +/Users/brownsarahm/Documents/inclass/systems/github-inclass-brownsarahm |
| 201 | +``` |
| 202 | + |
| 203 | + |
| 204 | +```bash |
| 205 | +cd .. |
| 206 | +pwd |
| 207 | +``` |
| 208 | + |
| 209 | + |
| 210 | +``` |
| 211 | +/Users/brownsarahm/Documents/inclass/systems |
| 212 | +``` |
| 213 | + |
| 214 | +## Adding a file from the command line |
| 215 | +First back to the repo directory |
| 216 | +```bash |
| 217 | +cd github-inclass-brownsarahm/ |
| 218 | +``` |
| 219 | + |
| 220 | +We will make an empty file for now, using `touch` |
| 221 | + |
| 222 | +```bash |
| 223 | +touch about.md |
| 224 | +``` |
| 225 | + |
| 226 | + |
| 227 | +```bash |
| 228 | +ls |
| 229 | +``` |
| 230 | +We can se the two folders |
| 231 | + |
| 232 | +``` |
| 233 | +README.md about.md |
| 234 | +``` |
| 235 | + |
| 236 | +We can see the file, but what does git know? |
| 237 | + |
| 238 | +```bash |
| 239 | +git status |
| 240 | +``` |
| 241 | + |
| 242 | + |
| 243 | +``` |
| 244 | +On branch main |
| 245 | +Your branch is up to date with 'origin/main'. |
| 246 | +
|
| 247 | +Untracked files: |
| 248 | + (use "git add <file>..." to include in what will be committed) |
| 249 | + about.md |
| 250 | +
|
| 251 | +nothing added to commit but untracked files present (use "git add" to track) |
| 252 | +``` |
| 253 | + |
| 254 | +First we have to add it to a staging are to make a batch of files (or only one) |
| 255 | +that will commit. |
| 256 | + |
| 257 | +```bash |
| 258 | +git add . |
| 259 | +``` |
| 260 | + |
| 261 | +THen we check in with git again |
| 262 | +```bash |
| 263 | +git status |
| 264 | +``` |
| 265 | + |
| 266 | + |
| 267 | +``` |
| 268 | +On branch main |
| 269 | +Your branch is up to date with 'origin/main'. |
| 270 | +
|
| 271 | +Changes to be committed: |
| 272 | + (use "git restore --staged <file>..." to unstage) |
| 273 | + new file: about.md |
| 274 | +
|
| 275 | +``` |
| 276 | +THen we can commit the file |
| 277 | + |
| 278 | +```bash |
| 279 | +git commit -m "create about" |
| 280 | +``` |
| 281 | + |
| 282 | +Git returns to us the commit number, with the message and a summary |
| 283 | +``` |
| 284 | +[main 3c9980a] create about |
| 285 | + 1 file changed, 0 insertions(+), 0 deletions(-) |
| 286 | + create mode 100644 about.md |
| 287 | +``` |
| 288 | +and again checkin |
| 289 | + |
| 290 | +```bash |
| 291 | +git status |
| 292 | +``` |
| 293 | + |
| 294 | + |
| 295 | +``` |
| 296 | +On branch main |
| 297 | +Your branch is ahead of 'origin/main' by 1 commit. |
| 298 | + (use "git push" to publish your local commits) |
| 299 | +
|
| 300 | +nothing to commit, working tree clean |
| 301 | +``` |
| 302 | + |
| 303 | +Now we see that the local copy is ahead of GitHub (aka origin), so we need to |
| 304 | +push to make the changes go to GitHub. |
| 305 | + |
| 306 | +```bash |
| 307 | +git push |
| 308 | + |
| 309 | +``` |
| 310 | + |
| 311 | + |
| 312 | +``` |
| 313 | +Enumerating objects: 4, done. |
| 314 | +Counting objects: 100% (4/4), done. |
| 315 | +Delta compression using up to 8 threads |
| 316 | +Compressing objects: 100% (2/2), done. |
| 317 | +Writing objects: 100% (3/3), 307 bytes | 307.00 KiB/s, done. |
| 318 | +Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 |
| 319 | +To https://github.com/introcompsys/github-inclass-brownsarahm.git |
| 320 | + ec3dd02..3c9980a main -> main |
| 321 | +(base) brownsarahm@github-inclass-brownsarahm $ |
| 322 | +
|
| 323 | +``` |
| 324 | + |
| 325 | +## Review |
| 326 | +```{include} ../_review/2022-09-14.md |
| 327 | +``` |
| 328 | + |
| 329 | + |
| 330 | + |
| 331 | + |
| 332 | +## Prepare |
| 333 | +```{include} ../_prepare/2022-09-14.md |
| 334 | +``` |
| 335 | + |
| 336 | + |
| 337 | + |
| 338 | + |
| 339 | +## More Practice |
| 340 | +```{include} ../_practice/2022-09-14.md |
| 341 | +``` |
| 342 | + |
| 343 | + |
| 344 | +## Questions at the end of class |
| 345 | + |
| 346 | + |
| 347 | +• can you add additional arguments to most git commands? ex git commit -... |
| 348 | + |
| 349 | +• why can't we make all of these files on github instead of using gitbash? |
| 350 | + |
| 351 | +• is there any advantages to using the github website vs using the github commands on your terminal |
| 352 | + |
| 353 | +• One question I have is, how would I edit a text file using bash |
| 354 | + |
| 355 | +• When working with a team what are ways we can prevent merging conflicts? |
| 356 | + |
| 357 | +• will we do the bulk of our work in-console or in an IDE, or a mix of both? |
| 358 | + |
| 359 | +• none |
| 360 | + |
| 361 | +• If we are confused about what is due for next class, which locations should we look? I think right now there are multiple, unless I am wrong about that. |
| 362 | + |
| 363 | +• I accidentally used the push command before the config command. Is that a problem? Is there anything I have to change? |
0 commit comments