## Notes * Need to update screenshots with directory structure from the end of bash section see .center[] * Include .gitignore discussion to show how to hide setup script (did this when teaching on 2023-10-12) * Ignore big data files, PHI, passwords, etc * One person had git in a non-standard location that RStudio couldn't find --- ## Notes (cont) * Windows had a pop up window when doing the first git push, had them pick token instead of the other options * Windows terminal within RStudio doesn't seem to use bash * When instructor zooms in on RStudio, you lose the labels next to icons (e.g., Commit, Push, Pull) * At end, would be good to see how an active research lab uses GitHub to serve up code/data/images for papers --- ## Notes (cont) * Got through "Modify your R script..." exercise * then talked through why you'd run git from the command line * emphasized that 98% of my git use is covered by RStudio * encouraged to get comfortable using git in RStudio before trying to use git on command line --- ## Notes (cont) * At the LICENSE part, I showed issue tracker * Simulated a conversation with PI * Picked the LICENSE * Committed changes and closed issue --- class: center, middle # Introduction to .center[] .center[] --- class: middle, center  .tiny[.lightgray[“Piled Higher and Deeper” by Jorge Cham]] --- class: middle, center .center[ ] --- class: middle, center .center[ ] .center[] --- class: middle, center .center[ ] --- class: middle, center .center[ ] --- class: middle, center  --- class: middle, center .center[ ] .center[] -- --- class: middle, center # One-time configurations --- class: middle, center .center[ ] --- class: middle, center .center[ ] --- ### User name Set a name that is identifiable for credit when review version history. ``` $ git config --global user.name "Pat Schloss" ``` -- ### User email Set an email address that will be associated with each history marker. ``` $ git config --global user.email "pdschloss@umich.edu" ``` --- # Line endings ### On macOS and Linux: ``` $ git config --global core.autocrlf input ```
### On Windows: ``` $ git config --global core.autocrlf true ``` --- ### Text editor ``` $ git config --global core.editor "nano -w" ``` -- ### Default Branch name ``` $ git config --global init.defaultBranch main ``` -- ### Credential storage ``` $ git config --global credential.helper store ``` --- ### View the configurations ``` $ git config --list ``` --- ## Now to initialize our repository .center[] --- ## Now to initialize our repository .center[] --- ## Using git - 98% of what you will do * Get versions of our files into repository * Attach a message to our files indicating what happened .center[] --- ## Untracked files .center[] --- ## Staging/adding our changes .center[] Once files checked, click check icon under "Environment" tab name --- ## Committing our changes .center[] Write "Initial commit" in message window --- ## Committing our changes .center[] * Click close * Notice that the staging window is now empty --- ## Create repository in GitHub - Open the GitHub website and sign in - Create a new repository with name .red[un-report] - Do not check the box to add a .red[README] file - Do not select a .red[.gitignore] file - Do not select a .red[LICENSE] file - Click .green[Create repository] button --- ## Connecting GitHub to your computer .center[] Make sure that HTTPS is selected and click copy button to the right of the "…or push an existing repository from the command line" section --- ## Connecting GitHub to your computer .center[] Enter your GitHub username and wait when asked for your password, we will use a personal access token --- ## Create Personal Access Token .center[ ] --- ## Create Personal Access Token .center[ ] --- ## Create Personal Access Token .center[ ] --- ## Create Personal Access Token .center[ ] --- ## Create Personal Access Token .center[ ] --- ## Create Personal Access Token .center[ ] --- ## Connecting GitHub to your computer .center[] * Where asked for your password paste the personal access token * We shouldn't be asked for password again for 90 (or whatever) days --- ## New file GitHub suggests adding a README file, let's do it from within RStudio .center[ ] Save the file as .blue[README.md] --- ## Let's type some text into the .blue[README.md] file ``` ## Notes for UN Report We plotted life expectancy over time. ``` -- Check out the change in the git staging window .center[ ] --- ## Stage, add and commit the change .center[ ] --- ## Let's add a line to README.md ``` We plotted life expectancy over time. Each point represents a country ``` -- Notice the change in the git staging window .center[ ] --- ## Commit the new changes .center[ ] Notice the "diff" at the bottom of the window indicating what has changed --- ## Exercise Follow the previous examples to... - Add a third line to the README.md ``` We plotted life expectancy over time. Each point represents a country. Continents are grouped by color. ``` - Stage and commit the above change - What happens if you click "View file @ XYZ1234" in the "Changes" view of an earlier commit? When would you want to use this? --- ## Exercise Which of the following commit messages would be most appropriate for the last commit? 1. “Changes” 1. “Added line ‘Continents are grouped by color.’ to notes.txt” 1. “Describe grouping” --- class: middle, center .center[]
.lightgray[Source: https://xkcd.com/1296/] --- ## Show the commit logs .center[] --- ## Let's edit our README.md file further .center[] --- ## Let's check out the diff before committing .center[] --- ## Let's stage and commit from the diff window .center[] --- ## How to get this up to GitHub? .green[Push]. Click the upward pointing arrow. .center[] --- ## GitHub changes .center[] --- ## GitHub commit history .center[] --- ## GitHub diffs .center[] --- ## Let's create a file on GitHub .center[] --- ## Let's create a file on GitHub .center[] --- ## Let's create a file on GitHub .center[] --- ## Let's create a file on GitHub .center[] --- ## Let's create a file on GitHub .center[] --- ## Let's commit changes on GitHub .center[] --- ## New file already on GitHub .center[] --- ## How do we get our file back to our local computer? .center[] --- ## How do we get our file back to our local computer? .red[Pull] .center[] --- ## Exercise * Modify your R script to include the following after the ggplot code chunk: ``` ggsave("figures/gdpPercap_lifeExp.png") ``` * Rerun the ggplot code chunk along with the following ggsave line * Update your REAMDE.md file * Stage the changes and new file, commit those changes, and push to GitHub --- ## Exercise * Create a new Git repository on your computer called workshop * Write three lines about what you have learned about R and bash a file called README.md, commit your changes * Modify one line, add a fourth line * Display the differences between its updated state and its original state * Push it to GitHub --- ## Why run git from the terminal? * RStudio and other git-based tools with a graphical user interface (GUI) have gotten really good over the past few years, especially for most of our needs -- * But they aren't as powerful as running the commands from the command line -- * Believe it or not, typing can be a lot faster than pointing and clicking! -- * If you need help doing something, Google likely point you to solutions using the command line -- * You don't always have access to a GUI (e.g., HPC) --- ## git from the terminal How do we look at the staging area? ``` $ git status ``` -- Modify README.md to include your name and the date ``` $ git status ``` -- See the change as git sees it ``` $ git diff ``` --- ## git from the terminal To stage the change (can add more than one file) ``` $ git add README.md $ git status ``` -- To commit the change ``` $ git commit -m "Added my name and date" $ git status ``` --- ## git from the terminal To push the changes ``` $ git push $ git status ``` -- To pull any changes (there aren't any) ``` $ git pull ``` Why might you want to pull from GitHub before committing any changes on your local computer? --- ## Exercise * Change the ColorBrewer palette to `Dark2` * Rerun the code and be sure to save the output with `ggsave` * Use `git status` to look at the staging area * Use `git diff` to look at what has changed * Stage, commit, and push your changes --- ## Collaboration .center[] --- ## Collaboration .center[] --- ## Collaboration .center[] --- ## From here... * Option 1: Fork repository / Create project from repository / Push / File pull request * Option 2: Clone repository to new project / Push to main user's repository * Option 3: Create feature branch / Clone repository to new project / Work on new feature branch / Push to main user's repository / Merge branches Cover how to handle merge conflicts?