class: center, middle, inverse, title-slide # Git & GitHub ### Bruna Wundervald ### PhD Candidate in Statistics, Hamilton Institute, Maynooth University ### October, 2018 --- ## What are git and GitHub? - **Git**: the most widely used modern version control system in the world today - Originally developed in 2005 by Linus Torvalds - **Github**: a web-based hosting service for version control using git. <b> <img src="https://www.enriquedans.com/wp-content/uploads/2018/06/GitHub-Octocat.jpg" width="30%" height="50%" style="display: block; margin: auto;" /> [Git Cheatsheet here!](https://www.atlassian.com/git/tutorials/atlassian-git-cheatsheet) --- ## Starting - [Download](https://git-scm.com/downloads) and install git. - Create a [GitHub](http://github.com) account. - Note that students are eligible to one year of premium account for free! - Connect you GitHub account to your local git using the SSH keys. **But what is a SSH key?** > An SSH key is an access credential in the SSH protocol. Its function is similar to that of user names and passwords, but the keys are primarily used for automated processes and for implementing single sign-on by system administrators and power users. --- ## Connecting local git and GitHub 1. Open the GitHub website and go to `Settings` -> `SSH and GPG keys` -> `New SSH key` 2. Open terminal and run (with your email, of course): `ssh-keygen -t rsa -b 4096 -C "your_email@example.com"` 3. Press enter till the end of the process. 4. On terminal, run `eval "$(ssh-agent -s)"` and `ssh-add ~/.ssh/id_rsa`. Now you have generated the key. The next step is to copy and paste it in GitHub: 5. Open the file created in `~/.ssh` and copy it to GitHub. More details here: https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/ --- # Basic git commands First, create a repository in GitHub, by clicking "Start a project". 1. Clone it in the path you want with terminal by running `git clone username/repositoryname` - If you don't have the permission to clone the repository, git you tell you! 2. Starting editing the folder! To push your changes to git, there are basically four steps: 1. Check what changed with `git status` 2. Add your changes with `git add changed_file.extension` - You can use `git add .` to add all of them! 3. Commit your changes with `git commit -m "commit message"` 4. Push your changes with `git push` Update git repositories with `git pull`! --- ## Branches - Branches are used to develop isolated functionalities in a git repository. <img src="https://cdn-images-1.medium.com/max/1600/1*iB8lNrITmLvKeL8mnp3qAA.png" width="70%" height="50%" style="display: block; margin: auto;" /> --- # Using branches 1. Create a new branch in the repo with `git checkout -b branch_name` 2. Now you're working on this branch. 3. Add your changes normally, except by the push step: now you need to use `git push branch_name` to identify where the changes are coming from. 4. Return to the master branch with git `checkout master` **At this point, the changes made using the branch are not** **available in the master folder. If everything is ok with** **the branch, you can `merge` ("accept") it with `git merge branch_name`** - This depends on the branch having no conflicts with the master branch. If conflicts exist, you might need to deal with them manually. It is possible to check the differences between branches with `git diff <origin branch> <destin branch>` --- ## Contributing to existing repositories Suppose you want to add changes to an existing repository - example: to discontinuated `R` packages. The steps to do that are: 1. `fork` the repository into your github account. <img src="https://github-images.s3.amazonaws.com/help/bootcamp/Bootcamp-Fork.png" width="40%" height="40%" style="display: block; margin: auto;" /> 2. Clone it (from your github account, e.g. `github.com/your_user/forked_repository`), make the changes and push it. 3. Make a `pull request` into the original repository, a.k.a. ask for your changes to be added by the owner of the repository. **Some repositories have their own contributing guide!** --- # Contributing scheme <img src="http://jlord.us/git-it/assets/imgs/clone.png" width="90%" height="70%" style="display: block; margin: auto;" /> --- class: center, middle ## Acknowledgments This work was supported by a Science Foundation Ireland Career Development Award grant number: 17/CDA/4695 <img src="SFI_logo.jpg" width="50%" height="40%" style="display: block; margin: auto;" /> --- class: center, middle, inverse # Thanks! <img src= "https://s3.amazonaws.com/kleebtronics-media/img/icons/github-white.png", width="50", height="50", align="middle"> <b> [@brunaw](https://github.com/brunaw)