class: center, middle, inverse, title-slide # Version Control: ## A Practical Introduction to Git and Github ###
Joseph V. Casillas
###
From Proposal to Publication: Pathways to Open Science | 07-14-2021
--- class: middle # Hi! ππΌ .Large[ | | | | ----------------------------------: | :-------------------------------------- | |
| joseph.casillas@rutgers.edu | |
| [@jvcasill](https://twitter.com/jvcasill) | |
| https://github.com/jvcasillas/github_workshop | |
| https://www.jvcasillas.com/github_workshop/index.html | ] --- exclude: true class: center, middle background-color: #fd9426 <iframe src="https://app.sli.do/event/ba48cucz/live/polls" width="1000" height="600" style="border:none;"></iframe> --- exclude: true class: center, middle background-color: #fd9426 <iframe src="https://wall.sli.do/event/ba48cucz" width="1000" height="600" style="border:none;"></iframe> --- class: middle # What are we going to do today? -- .Large[ 1. What is version control and why do I care? 2. Get familiar with Git/Github ] ??? get familiar with git/github understand conceptually what it is, what it does, what it is for learn how it can be a tool for our research (safety measures, promote open science) open doors for collaboration --- class: middle background-image: url("./assets/img/final_doc.png") background-size: 525px background-position: 100% 50% # What is version control? ??? Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later --- background-image: url("./assets/img/data_science1.png") background-size: contain --- background-image: url("./assets/img/data_science3.png") background-size: contain --- background-image: url("./assets/img/datascience_workflow.png") background-size: contain -- .center[.big[**This process should be version controlled!**]] --- background-image: url("./assets/img/datascience_workflow2.png"), url(./assets/img/workflow_10.png) background-size: 600px, 700px background-position: 15% 90%, 95% 40% -- .center[.big[**This project should be version controlled!**]] --- class: title-slide-section-grey, middle background-image: url("./assets/img/final_doc.png") background-size: 525px background-position: 100% 50% # .white[So what is version control?] -- # **Recording changes to a file<br>or set of files over time so<br>that you can recall specific<br>versions later** --- background-image: url(./assets/img/vc1_github_01.png) background-size: contain count: false --- background-image: url(./assets/img/vc1_github_02.png) background-size: contain count: false --- background-image: url(./assets/img/vc1_github_03.png) background-size: contain count: false --- background-image: url(./assets/img/vc1_github_04.png) background-size: contain count: false --- background-image: url(https://octodex.github.com/images/hula_loop_octodex03.gif) background-size: 300px background-position: 90% 10% # Version control ### How do we do it for reproducible research? .big[ - Git - Github - Gitlab - Bitbucket ] --- class: title-slide-section-red, middle background-image: url(https://media.giphy.com/media/3o7aTwT5vjBVfsYEj6/giphy.gif) background-size: 500px background-position: 90% 50% # What you'll need... --- <br> .left-column[ ## .black[What you'll need] .Large[ - .RUred[Git] - .RUgrey[GitHub account] - .RUgrey[Github Desktop] ] ] .right-column[ ## **Git** .Large[ - Installation and setup: https://git-scm.com/book/en/v2/Getting-Started-Installing-Git - Troubleshooting: https://happygitwithr.com/install-git.html - You should have this already π ] ] --- <br> .left-column[ ## .black[What you'll need] .Large[ - .RUgrey[Git] - .RUred[GitHub account] - .RUgrey[Github Desktop] ] ] .right-column[ ## **GitHub** .Large[ - It's free - Use an academic email if you have one (more perks) - Give consideration to your username - avoid spaces, uncommon characters - shorter is better than longer - usually your real name (or related to it) - You should have this already π ] ] --- <br> .left-column[ ## .black[What you'll need] .Large[ - .RUgrey[Git] - .RUgrey[GitHub account] - .RUred[Github Desktop] ] ] .right-column[ ## **GitHub Desktop** .Large[ - This will make interacting with Git much easier - You can download the app here: https://desktop.github.com - You should have this already π ] ] --- class: middle background-image: url(https://raw.githubusercontent.com/jvcasillas/media/master/teaching/img/think.png) background-size: 400px background-position: 90% 50% # What is Git? --- background-image: url(https://git-scm.com/images/logos/downloads/Git-Icon-1788C.png) background-size: 250px background-position: 95% 50% # Git ### What is it? <br> .Large[ - Open source version control system ] -- .Large[ - Keeps track of changes you make to files ] -- .Large[ - Conceptually similar to dropbox/box/google drive/<br>one drive/etc., "but for nerds" ] --- background-image: url(https://git-scm.com/images/logos/downloads/Git-Icon-1788C.png) background-size: 250px background-position: 95% 50% # Git ### How does it work? .pull-left[ .Large[ - Git keeps track of incremental changes in project files - We can think of it like taking snapshots of a repository (project) π· - We access Git via **the command line** ] ] -- background-image: url(https://raw.githubusercontent.com/jvcasillas/media/master/teaching/gifs/scared.gif) background-size: 325px background-position: 95% 50% --- background-color: black background-image: url(https://www.redhat.com/sysadmin/sites/default/files/styles/full/public/2020-12/linux-command-line-ls-output.jpg?itok=3mL5X-30) background-size: contain <!-- COMMAND LINE IMAGE --> --- class: middle background-image: url(https://raw.githubusercontent.com/jvcasillas/media/master/teaching/gifs/confused.gif) background-size: 600px background-position: 93% 50% # What is Github? --- background-image: url(./assets/img/octocat_rainbow.png) background-position: 93% 50% background-size: 300px # Github ### What is it? <br> .Large[ - An online interface to Git - A place to store repositories (projects) - Owned by microsoft π ] --- class: title-slide-section-red, center, middle # Walk-through ??? profile, repos, public, private not to late to catch up --- class: middle background-color: black .pull-left[ # **Git** .Large[ .white[a version control system that let's you manage and keep track of your source code history via repositories] ] ] .pull-right[ # **Github** .Large[ .white[a cloud based hosting service that lets you manage Git repositories] ] ] --- background-color: black background-image: url(./assets/img/github101.png) background-size: 700px <!-- Exercise I create repo (projects) create text file commit changes (key ideas: repo, commit) (tips: think carefully about names) --> --- class: title-slide-section-red background-image: url(https://octodex.github.com/images/daftpunktocat-thomas.gif), url(https://github.githubassets.com/images/modules/logos_page/GitHub-Logo.png) background-size: contain, 400px background-position: 100% 50%, 20% 85% # Exercise I --- background-image: url(./assets/img/new_repo_icon.png), url(./assets/img/new_repo_menu.png) background-size: 300px, 300px background-position: 95% 15%, 95% 75% # Exercise I ## Your first repo ### 1. Create new repository .big[ - Option a) Click the **New** icon anywhere - Option b) Click on the profile icon in the<br>upper right hand corner, from the<br>dropdown menu select **Your repositories**,<br>click the **New** icon ] --- count: false background-image: url(./assets/img/name_repo.png) background-size: 600px background-position: 95% 50% # Exercise I ## Your first repo ### 2. Name your repo **my-repo** and<br>check the box for **Add a README file** --- count: false background-image: url(./assets/img/create_repo.png) background-size: 700px background-position: 60% 85% # Exercise I ## Your first repo ### 3. Click **Create repository** --- count: false background-image: url(https://raw.githubusercontent.com/jvcasillas/media/master/teaching/gifs/rock_clap.gif) background-size: contain --- count: false background-image: url(./assets/img/readme.png) background-size: 600px background-position: 50% 85% # Exercise I ## Your first repo ### 4. Click **README.md** --- count: false background-image: url(./assets/img/pencil_icon.png) background-size: 500px background-position: 50% 55% # Exercise I ## Your first repo ### 5. Click the pencil icon and edit the file by adding some text --- count: false background-image: url(./assets/img/commit_icon.png) background-size: 400px background-position: 50% 75% # Exercise I ## Your first repo ### 6. Scroll to the bottom and click **Commit changes** --- # Exercise I - Review .big[ 1. Create new repository - Option a) Click the **New** icon anywhere - Option b) Click on the profile icon in the upper right hand corner, from the dropdown menu select **Your repositories**, click the **New** icon 2. Name your repo **my-repo** and<br>check the box for **Add a README file** 3. Click **Create repository** 4. Click **README.md** 5. Click the pencil icon and edit the file by adding some text 6. Scroll to the bottom and click **Commit changes** ] --- background-image: url(https://octodex.github.com/images/puddle_jumper_octodex.jpg) background-size: 300px background-position: 94% 10% # Exercise I - Review ### Key ideas .big[ - **Repositories** are projects - We **commit** changes to the repository - **README** files have special status on Github ] ### Tips .big[ - Remember to think carefully about names - Avoid spaces and uncommon characters (if possible) ] --- exclude: true count: false class: center, middle background-color: #fd9426 <iframe src="https://wall.sli.do/event/ba48cucz" width="1000" height="600" style="border:none;"></iframe> <!-- Exercise II clone repo to our machine commit changes push changes (key ideas: clone, commit, push) (tips: think carefully about where projects live) git clone REPO --> --- background-image: url(./assets/img/clones.png) background-size: contain # Exercise II <!-- storm trooper img --> --- background-image: url(./assets/img/ex2_clone1.png) background-size: contain --- count: false background-image: url(./assets/img/ex2_clone2.png) background-size: contain --- count: false background-image: url(./assets/img/ex2_clone3.png) background-size: contain --- count: false background-image: url(./assets/img/ex2_clone4.png) background-size: contain --- count: false background-image: url(./assets/img/ex2_clone5.png) background-size: contain --- class: title-slide-section-red, middle, center # Walk-through --- background-image: url(https://octodex.github.com/images/snowoctocat.png) background-size: 250px background-position: 93% 10% # Exercise II ### Cloning .big[ 1. Clone **my-repo** repo on to your computer (Github desktop: File > Clone repository) 2. Edit the README.md file using a text editor<br>and put some text in the body 3. Save everything, commit the changes to origin with<br>an informative message 4. Push changes from your local (cloned) repo to origin (the cloud) 5. Check github to see if it worked ] --- # Exercise II - Review ### Key ideas - We **clone** repositories from **origin** to our computers (**local** copies) - We work like normal and **commit** changes - When we finish we **push** changes from our local copy to origin - The changes are then visible on Github ### Tips - Always think carefully about where projects live - Practice this procedure (clone > edit > commit > push) with dummy repos to get the hang of it - Don't be afraid to burn the house down --- exclude: true class: center, middle background-color: #fd9426 <iframe src="https://wall.sli.do/event/ba48cucz" width="1000" height="600" style="border:none;"></iframe> --- class: middle # What this means... --- count: false background-image: url(./assets/img/vc1_github_05.png) background-size: contain --- count: false background-image: url(./assets/img/vc1_github_06.png) background-size: contain --- count: false background-image: url(./assets/img/vc1_github_07.png) background-size: contain --- count: false background-image: url(./assets/img/vc1_github_08.png) background-size: contain --- count: false background-image: url(./assets/img/vc1_github_09.png) background-size: contain --- count: false background-image: url(./assets/img/vc1_github_10.png) background-size: contain --- exclude: true count: false class: center, middle background-color: #fd9426 <iframe src="https://wall.sli.do/event/ba48cucz" width="1000" height="600" style="border:none;"></iframe> <!-- fork repo from github clone to local machine make changes commit changes push changes submit PR (key ideas: fork, clone, commit, push) --> --- class: bottom background-color: black background-image: url(https://octodex.github.com/images/grim-repo.jpg) background-size: contain # Exercise III --- background-image: url(https://octodex.github.com/images/steroidtocat.png) background-size: 300px background-position: 90% 10% # Exercise III ### Collaborating with forks .big[ 1. **Fork** the github_practice repo 2. Clone repo to your computer 3. Open the README.md file 3. Edit README.md 4. Commit changes 5. Push changes to origin (your copy on Github) 6. Submit a **pull request** ] --- background-image: url(./assets/img/vc1_github_15.png) background-size: contain --- background-image: url(./assets/img/vc1_github_16.png) background-size: contain --- background-image: url(./assets/img/vc1_github_17.png) background-size: contain --- background-image: url(https://octodex.github.com/images/socialite.jpg) background-size: contain --- class: title-slide-section-red, middle, center # Walk-through --- background-image: url(https://octodex.github.com/images/steroidtocat.png) background-size: 300px background-position: 90% 10% # Exercise III ### Collaborating with forks .big[ 1. **Fork** the github_practice repo 2. Clone repo to your computer 3. Open the README.md file 3. Edit README.md 4. Commit changes 5. Push changes to origin (your copy on Github) 6. Submit a **pull request** ] --- background-image: url(https://octodex.github.com/images/steroidtocat.png) background-size: 300px background-position: 90% 10% # Exercise III - Review ### Key ideas - We can **fork** other peoples repos - We can then *clone* our **forked** copy and make changes - Edit > commit > push - We can send our modifications to the original repo via **pull requests** ### Tips - Learn from other people by forking their projects π - It is extremely fulfilling to contribute to other people's projects π - If you get stuck/make a mistake you can always burn the house down π₯ --- exclude: true class: center, middle background-color: #fd9426 <iframe src="https://wall.sli.do/event/ba48cucz" width="1000" height="600" style="border:none;"></iframe> --- background-image: url(https://octodex.github.com/images/labtocat.png) background-size: 300px background-position: 90% 10% # Git/Github ### Metaphors and terminology .big[ - repo - commit - clone - push - pull - fork - pull request **there are more** ] --- background-image: url(https://raw.githubusercontent.com/jvcasillas/media/master/general/gifs/throw_into_pool.gif) background-size: 500px --- class: middle background-image: url(https://octodex.github.com/images/femalecodertocat.png) background-size: 300px background-position: 90% 50% # Next steps... .big[ - Branches - Merge conflicts - The command line ] --- count: false class: title-slide-final background-image: url(https://github.com/jvcasillas/ru_xaringan/raw/master/img/logo/ru_shield.png), url(https://octodex.github.com/images/spidertocat.png) background-size: 70px, 250px background-position: 15% 15%, 95% 0% <br> # Thank you! <br><br><br><br><br> .Large[ | | | | ----------------------------------: | :-------------------------------------- | |
| .lightgrey[joseph.casillas@rutgers.edu] | |
| .lightgrey[@jvcasill] | |
| .lightgrey[https://github.com/jvcasillas/github_workshop] | |
| .lightgrey[https://www.jvcasillas.com/github_workshop/index.html] | ] .left[.footnote[.large[Hint: continue for more tips and tricks!]]] --- count: false class: title-slide-section-grey, middle, center # More about projects --- count: false class: middle, center # Workflows and projects ### What does your workflow currently look like? ### What do you organize for? ### How do you do it? ### Where do your files live? --- count: false # RStudio projects ### If your projects include R scripts, RMarkdown documents, HTML slides, etc., you should be using RStudio projects -- count: false - What are they? -- count: false .content-box-blue[ `.rproj` files create an independent RStudio environment that limits the scope of your R session to the project in question. ] -- count: false - Why use them? -- count: false - They simplify organizing projects - They integrate well with github - They promote a project-oriented workflow --- count: false class: title-slide-section-grey, middle, center # What's in a project anyway? --- count: false # Directory structure ### Student .big[ - class notes - articles - misc. documents - final project - homework ] -- count: false background-image: url(./assets/img/student_project.png) background-size: 700px background-position: 95% 50% --- count: false background-color: black background-image: url(./assets/img/student_project.png) background-size: contain --- count: false # Directory structure ### Researcher .big[ - data - scripts - manuscript - slides - READMEs ] -- count: false background-image: url(./assets/img/researcher_project.png) background-size: 700px background-position: 95% 50% --- count: false background-color: black background-image: url(./assets/img/researcher_project.png) background-size: contain --- count: false # Directory structure ### A note on READMEs .pull-left[ .large[ - Every folder/directory should have a README.md file that explains... - the purpose of the folder - the contents of the folder - any keys/glossaries necessary to understand the contents of the folder - timestamps - etc. ] ] .pull-right[ <blockquote align='center' class="twitter-tweet" data-lang="de"> <a href="https://twitter.com/jvcasill/status/1033406317304709122?s=12"></a> </blockquote> ] --- count: false class: title-slide-section-grey, middle, center # Say my name --- count: false # Naming conventions ### Why? - You probably don't spend much time thinking about how you name files and documents - You should - The idea is to follow a few simple guidelines that will make facilitate organizing your projects and make the file structure easily searchable --- count: false # Naming conventions ### How? .pull-left[ - Use descriptive names - .red[Bad]: `Experiment` - .blue[Good]: `qualifying_paper_1` - no capitals, no spaces (use `_` or `-`) - .red[Bad]: `Experiment for syntax class` - .blue[Good]: `semantic_predictability_exp_1` - no non-standard characters - .red[Bad]: `Analysis of Γ° for ICPhS 2019` - .blue[Good]: `spirantization_icphs_2019` ] -- count: false .pull-right[ - Numbers: use 2 places minimum, year-month-day - .red[Bad]: `Analysis 1` - .blue[Better]: `01_analysis` - .green[Best]: `2019-02-20_data_download` ] -- count: false background-image: url(./assets/img/numbers.png) background-size: 400px background-position: 90% 90% --- count: false class: title-slide-section-grey, middle, center # Github integration --- count: false background-color: black background-image: url(./assets/img/github01.png) background-size: contain --- count: false background-color: black background-image: url(./assets/img/github02.png) background-size: contain --- count: false class: title-slide-section-grey, center, middle # Tips and tricks --- count: false # Tips and tricks ### Nested projects - You can have RStudio projects inside of larger projects - Only the larger project is a repo - Ex. - Project: `dissertation` (β repo) - Nested project: `production_semantic_processing_las` - Nested project: `prod_perc_bilabials_jphon` -- count: false ### Alfred - Productivity app - Only on Mac (I think), free - Works like Spotlight search, but customizable - Set to search for `.rproj` files - Allows you to quickly open and close RStudio projects --- count: false class: title-slide-section-grey, middle, center # Advanced --- count: false # Review .big[ - There are different types of workflows when using github <p></p> - Standard way: - Create repo - Clone local copy - Make changes - Commit/push changes to remote ] --- count: false background-image: url(./assets/img/vc3_github_01.pdf) background-size: contain --- count: false background-image: url(./assets/img/vc3_github_02.pdf) background-size: contain --- count: false background-image: url(./assets/img/vc3_github_09.pdf) background-size: contain --- count: false background-image: url(./assets/img/vc3_github_10.pdf) background-size: contain --- count: false background-image: url(./assets/img/vc3_github_11.pdf) background-size: contain --- count: false # Review .big[ - There are different types of workflows when using github <p></p> .lightgrey[ - Standard way: - Create repo - Clone local copy - Make changes - Commit/push changes to remote ] <p></p> - When collaborating: - Fork repo - Clone local copy - Make changes - Commit/push changes to remote - Submit pull request to origin ] --- count: false background-image: url(./assets/img/vc3_github_03.pdf) background-size: contain --- count: false background-image: url(./assets/img/vc3_github_04.pdf) background-size: contain --- count: false background-image: url(./assets/img/vc3_github_05.pdf) background-size: contain --- count: false background-image: url(./assets/img/vc3_github_06.pdf) background-size: contain --- count: false class: bottom, center background-image: url(https://octodex.github.com/images/socialite.jpg) # Useful workflow when collaborating with many people --- count: false background-image: url(./assets/img/vc3_github_07.pdf) background-size: contain --- count: false background-color: #EDEDED background-image: url(./assets/img/vc3_github_08.pdf) background-size: contain --- count: false class: title-slide-section-grey, middle # **But**... ### ...this isn't the most common method -- count: false ### ...or the best method --- count: false background-color: black background-image: url(https://i.imgflip.com/2x4s1d.jpg) background-size: contain --- count: false background-color: black background-image: url(https://user-images.githubusercontent.com/194400/32239744-57300018-be63-11e7-8464-1389b9f8e0ee.png) background-size: contain --- count: false background-image: url(https://cdn2.hubspot.net/hubfs/2249672/Imported_Blog_Media/austin_powers-1.jpg) background-size: 500px background-position: 97% 50% # What gives? .pull-left[ .big[ - In the programming world committing to master is a nono. Why? - Most developers use git as version control for software - The .blue[master branch] is usually left for public releases - As such it should always work ]] --- count: false background-image: url(https://cdn-images-1.medium.com/max/1600/1*ezl84iQSMDnfkOipMVHgDw.png) background-size: 350px background-position: 97% 50% # What's the problem .pull-left[ .big[ - You might break something - You might get complicated merge conflicts ] .full-width[.content-box-blue[ Person A is working on the same file as Person B, they both make changes and Person A tries to submit a pull request to master on a file that is different from when (s)he started ]] ] --- count: false # What's the solution? ### Branches - Using branches gives us a way to work on different versions of a repository at one time -- count: false - By default a new repo has one branch called .large[.blue[master]] -- count: false - Master is *the definitive* branch -- count: false - We create new branches to experiment, make edits, create new features, etc., before committing them to master -- count: false - When you create a branch off of master youβre essentially making a copy, or snapshot of master at a specific point in time (like making a copy of a word file, i.e., `essay_final_version3_for_real.docx`) -- count: false - A branch should be used for making 'one logical change', usually to add a feature in software development -- count: false - If a collaborator makes changes to master while you are working on a branch, you can pull in those changes --- count: false background-image: url(./assets/img/vc3_github_12.pdf) background-size: contain --- count: false background-image: url(./assets/img/vc3_github_13.pdf) background-size: contain --- count: false background-image: url(./assets/img/vc3_github_14.pdf) background-size: contain --- count: false background-image: url(./assets/img/vc3_github_15.pdf) background-size: contain --- count: false background-image: url(https://guides.github.com/activities/hello-world/branching.png) background-size: contain --- count: false background-image: url(./assets/img/psychopy_network.png) background-size: contain --- count: false # Yeah, but... academic writing is different .big[ - Using branches in many cases may be overkill, depending on what your working on, i.e., slides for class ] -- count: false <p></p> .big[ - But there are concrete examples where it makes sense to use branches... - when collaborating with others - when working on large projects - when making revisions to a manuscript - when making changes to your website, cv, conference presentation/poster - whenever breaking something small will have a large impact on the project - whenever the possibility of "going back" needs to be controlled and easily achieved ] --- count: false background-image: url(./assets/img/diss_ex_1.png) background-size: 700px --- count: false background-image: url(./assets/img/diss_ex_2.png) background-size: contain --- count: false background-image: url(./assets/img/diss_ex_3.png) background-size: 700px --- count: false # Summary - workflows ### Old way - Working solo: commit/push to master -- count: false (.red[medium danger]) -- count: false - Working as collaborator: commit/push to master -- count: false (.red[danger]!) -- count: false - Working as outside collaborator: fork, commit/push to remote, pull request to master -- count: false (.red[low danger]) -- count: false background-image: url(https://user-images.githubusercontent.com/194400/32239878-ad220b4c-be63-11e7-82f0-49180949fb8e.png) background-size: 300px background-position: 97% 50% ### Better way - Working solo: branch, commit/push, pull request -- count: false - Working as collaborator, branch, commit/push, pull request -- count: false - Working as outside collaborator: fork, branch, commit/push, pull request --- count: false class: middle, inverse background-image: url(https://user-images.githubusercontent.com/194400/32239666-10da8f34-be63-11e7-928f-c00f552dd2c5.png) background-size: contain