class: center, middle, inverse, title-slide # Git Workshop ###
Janus Valberg-Madsen
### 2018-10-22 @ Aalborg University --- # Overview of today -- 1. What is version control, and why should I care? -- 1. Overview of the most important Git functions -- 1. Overview of GitHub -- 1. Live demo showcasing the concepts -- 1. **(interactive)** Install Git and a client -- 1. **(interactive)** Set up a repository on GitHub for your P1 project -- 1. Exercises (if there's time left) --- # Why use a version control system (VCS)? -- - You have an annotated history of changes -- - It makes collaboration easy -- - It provides you with a full backup of your project -- - Unlike on services like Dropbox, conflicts are structured and easily resolved -- ## Why Git, specifically? -- - Distributed (as opposed to centralised) -- - Most popular ⟹ all problems have been had -- - GitHub --- name: concepts class: center, middle, inverse # Git concepts (functions) --- ## The main components of a Git repository <img src="figs/repo-comp.svg" width="85%" style="display: block; margin: auto;" /> --- ## Add: stage changes for committing <img src="figs/git-add.svg" width="85%" style="display: block; margin: auto;" /> --- ## Commit: append staged changes to history <img src="figs/git-commit.svg" width="85%" style="display: block; margin: auto;" /> --- ## Push: changes on local repo ⭢ remote repo <img src="figs/git-push.svg" width="85%" style="display: block; margin: auto;" /> --- ## Push: changes on local repo ⭢ remote repo (before) <img src="figs/git-push-before.svg" width="85%" style="display: block; margin: auto;" /> --- ## Push: changes on local repo ⭢ remote repo (after) <img src="figs/git-push-after.svg" width="85%" style="display: block; margin: auto;" /> --- ## Pull: changes on remote repo ⭢ local repo (before) <img src="figs/git-pull-before.svg" width="85%" style="display: block; margin: auto;" /> --- ## Pull: changes on remote repo ⭢ local repo (after) <img src="figs/git-pull-after.svg" width="85%" style="display: block; margin: auto;" /> -- **Fetch** - "Safe" alternative to push - Downloads commits _without_ applying them to the working tree --- name: branches layout: true ## Branches - Branches are simply labels pointing to commits - Git uses these labels to move around in the commit history --- --- <img src="figs/git-branch-before.svg" width="85%" style="display: block; margin: auto;" /> --- <img src="figs/git-branch-after.svg" width="85%" style="display: block; margin: auto;" /> --- layout: true ## Checkout: switch to a different branch --- <img src="figs/git-checkout-before.svg" width="85%" style="display: block; margin: auto;" /> --- <img src="figs/git-checkout-after.svg" width="85%" style="display: block; margin: auto;" /> --- layout: false ## Merge: apply changes from a different branch <img src="figs/git-merge.svg" width="85%" style="display: block; margin: auto;" /> --- ## Overview <img src="figs/git-overview.svg" width="85%" style="display: block; margin: auto;" /> --- name: github # <img src="imgs/octicons/mark-github.svg" height="44" width="44" alt="icon"> GitHub <img src="imgs/gh-repo.png" width="75%" style="display: block; margin: auto;" /> --- ## View and comment on commits <img src="imgs/gh-commit-comment.png" width="100%" style="display: block; margin: auto;" /> --- ## Keep track of tasks with project boards <img src="imgs/gh-projects.png" width="100%" style="display: block; margin: auto;" /> --- ## Workflow <img src="figs/gh-collab.svg" width="75%" style="display: block; margin: auto;" /> --- name: demo class: center, middle, inverse # Time for a demo ⤷ on Windows with GitHub Desktop --- name: setup class: center, middle, inverse # Time to set up Git and GitHub ⤷ and get your project repository ready to go --- .pull-left[ # Installing Git ### Windows and macOS Download from <https://git-scm.com/> Windows users may have to restart after installation to update the system PATH ### Linux Install via package manager, e.g. ```sh sudo apt install git ``` ] .pull-right[ # Installing a client [Many options](https://git-scm.com/downloads/guis/), but to highlight a few: ♟ [**GitHub Desktop**](https://desktop.github.com/) ⤷ very simple client, only most basic features; integrates with GitHub ♜ [**GitKraken**](https://www.gitkraken.com/) ⤷ more features, fancy UI; free for _non-commercial_ use, requires account or GitHub sign-in ♛ **Your editor of choice** ⤷ many editors support version control from inside the editor<br> .small[(e.g. Emacs with Magit, or Vim with Fugitive)] ♚ **The command line** 😏 ] --- name: github # Collaborate with GitHub ❗ signing up with uni email ⟹ free private repos -- ## Getting started 1. Go to [**github.com**](https://github.com) and sign up with your `@student.aau.dk` email 2. Go to [**education.github.com/pack**](https://education.github.com/pack) and click _Get your Pack_ --- layout: true ## Setting up a repository (for the repo owner) _NB: Only one person from each group needs to set up a project repository_ --- 1. On GitHub, log in and click .gh-btn[<img src="imgs/octicons/repo.svg" height="20" width="20" alt="icon">New] 1. Fill in the details; - **Repository name:** P1 - **Description:** P1 project for Group `<your group id>` - **🗹 Private** (can be set later, if you don't have the student discount yet) - **🗹 Initialize this repository with a README** - **Add .gitignore:** TeX 1. Go to .gh-menu[<img src="imgs/octicons/gear.svg" height="20" width="20" alt="icon">Settings] 🠪 .gh-menu[Collaborators] 1. Add each of your group members as a collaborator 1. Go to .gh-menu[<img src="imgs/octicons/code.svg" height="20" width="20" alt="icon">Code] and click .gh-btn[Clone or download<img src="imgs/octicons/chevron-down.svg" height="20" width="20" alt="icon">] 1. Click .gh-menu[Open in Desktop] to get started (or copy the URL and open it with your Git client, if you don't use GitHub Desktop) --- 1. Download a template from [**janusvm.github.io/aau-project-template**](https://janusvm.github.io/aau-project-template/) 1. Unpack it in the folder where you cloned the project 1. In GitHub Desktop (or whatever client you use), stage all the new files 1. Commit with a message like "Add project template files" 1. Push to GitHub --- layout: false ## Setting up a repository (for the collaborators) 1. Go to the repository page on GitHub (github.com/owner/repo) 1. Click .gh-btn[Clone or download <img src="imgs/octicons/chevron-down.svg" height="20" width="20" alt="icon">] 1. Clone the repository (by clicking .gh-menu[Open in Desktop] with GH Desktop, or by using the URL with another client) After this, you're ready to start writing! --- ## Remember the workflow 1. **Pull** from GitHub to get the latest changes from the other group members 1. Work on the project 1. **Add** and **Commit** related changes together 1. **Pull** again, in case new commits have been pushed in the meantime 1. If there are any conflicts, resolve them and commit the merge 1. **Push** your changes to GitHub, so the other group members can get them --- name: exercises # Exercises .center[✨ **_[learngitbranching.js.org](https://learngitbranching.js.org)_** ✨] ## Links and help - These slides: [janusvm.github.io/aau-git-workshop](https://janusvm.github.io/aau-git-workshop) - Very simple introduction to Git: [think-like-a-git.net](http://think-like-a-git.net/) - More comprehensive tutorials: [www.atlassian.com/git/tutorials](https://www.atlassian.com/git/tutorials) - Tips on writing commit messages: [chris.beams.io/posts/git-commit](https://chris.beams.io/posts/git-commit/) - Fixing mistakes: [sethrobertson.github.io/GitFixUm/fixup.html](http://sethrobertson.github.io/GitFixUm/fixup.html) - Google .gh-menu[:^)] Feel free to ask questions too!