class: center, middle, inverse, title-slide .title[ # DS 202 - git and github ] .author[ ### ] --- # git and github ## Why git? <img src="http://imgs.xkcd.com/comics/git_2x.png" width=300> http://xkcd.com/1597/ --- ## What is git? - **Git** is a *version control system* that was created to help developers manage collaborative software projects. Git tracks the evolution of a set of files, called a **repository** or **repo**. - This helps us - *merge* conflicts that arise from collaboration - *rollback* to previous versions of files as necessary - store *master* versions of files, no more `paper_final_final_I_really_mean_it.docx` --- ## GitHub [GitHub](github.com) is one of many hosting services (others are e.g. [Bitbucket](bitbucket.org), [GitLab](about.gitlab.com), etc.). <img src="images/github.png" width=400> --- class:inverse ## Your Turn (5 min) This Your Turn is just a prep to get ready for a bigger Your Turn later. It'll take a couple of minutes of your time, but may need more time from github ... Here goes: Do you have a github account? - No? Create a _free_ account at https://github.com/ - Yes? Then log into it. - Do you remember your login and password? If not, try out different emails and let github send you the info. --- ## Git Terminology from [github glossary](https://help.github.com/articles/github-glossary/) - **Repository:** the basic element of git - like a project's folder. A repository contains all of the project files, and their __revision history__. One person owns a repository, multiple people can collaborate. Can be either public or private. - **Remote:** This is the version of something that is hosted on a server. It can be (and usually is) connected to a local clone. - **Clone:** A local copy of a repository that lives on your computer instead of on a website's server somewhere - **Fork:** a remote copy of a repository stored under your account.Forks allow you to freely make changes to a project without affecting the original. --- ## Terminology (cont'd) - **Pull:** When you are fetching changes from the remote repository and merging them with your local clone. - **Commit:** A checkpoint for the local clone to save changes to a file (or set of files). Every time you commit, git creates a unique ID that allows you to keep record of what changes were made when and by who. - **Push:** Sending your committed changes to the remote repository. --- ## Terminology (cont'd) - **Pull Request:** Proposed changes to a repository submitted by a user and accepted or rejected by a repository's collaborators. - **Issue:** Issues are suggested improvements, tasks or questions related to the repository. --- ## Repositories By default, all materials on GitHub are **public**. This is *good* because you are getting your work out there and contributing to the open source community! If you need **private** repos, checkout [GitHub for Education](https://education.github.com/) - free private repos for students/postdocs/professors. ![](images/github-icon.png) --- # Let's try to use git in class! ## Overview In this activity you are going to learn how to collaborate using Github. With a partner you will learn some basics which allow you to share and edit files on Github. 1. Create a git repository hosted at GitHub 2. Build `README.md` file 3. Commit changes to repository 3. Collaborate by forking and editing partners file 4. Explore Github features: graphs, diff, blame, ect. --- class: inverse ## Create a repository with a README.md file (10 minutes) **Step 1**: First we are going to create a repository within our Github user account. Follow along with your instructor and perform these steps: 1. Go to your Github profile. The url should be [http://github/your-user-name](). 2. Create a new Github repository, click <span style="background:limegreen; color:white">new</span> button, under the repositories tab. 3. Name your repository `ds202-your-name` 4. In the details write "ode to an academic advisor". 5. Click the initiate a `README.md file` option. --- ## So far - Once the repository is created you will be directed to the repository page which now has its own web address. - Each repository on Github has a unique url so you can easily share. - The git history is a detailed history of all the changes made to that file. One of the features of using Github is the ability to view your repository history which are displayed in the Graphs section of your Github repository page. - At this point in the git history of your `ds202-your-name` repository there is only one commit. --- class: inverse ## Edit the `README.md` file (5 minutes) 1. Go to the `ds202-your-name` repository main page. Click on `README.md`, then click "edit this file". Add the following information into the `README.md` file: - a crappy: what's the worst thing that happened since school started? - a happy: what's the best thing that happened since school started? *tip*: Notice that you can use markdown syntax. Use [this guide](https://help.github.com/articles/markdown-basics/) for Github's flavor of Markdown. Use the "Preview" button to view the formatting of your readme.md file. --- class: inverse ## Now let's combine all the happies and crappies! (5 minutes) 1. Go to repo https://github.com/DS202-at-ISU/ds202-sandbox 2. Fork the repo to your user. 3. Open the README.md file and include your Happy and Crappy. 4. Create a pull request to the original `ds202-sandbox` 5. You might have to fix a few merge issues (because everybody is trying to make changes right now 😄 ) --- ## git and GitHub in this class - use git and github for labs (Github Classroom), and the final project - all class materials are in a github repo - RStudio supports git integration in projects --- ## RStudio and git - [Install git](https://happygitwithr.com/install-git.html) or update it - Chapter 7: [Introduce yourself to git](https://happygitwithr.com/hello-git.html) ```r ## install.packages("usethis") library(usethis) ## check your configuration gert::git_config() use_git_config(user.name = "Jane Doe", user.email = "jane@example.org", scope = "user") ``` - Getting a [Personal Access Token](https://happygitwithr.com/https-pat.html). ```r usethis::create_github_token() ``` - Copy it and store your credentials: ```r gitcreds::gitcreds_set() ```