class: center, middle # Collaboration with git & Gitlab
--- # Why _git_ **Change control** - keep track of who changed what - revert changes easily ```bash no more presentation_v2_final_FINAL.pptx ``` **Backup & distribute** - store important files remotely - easily copy and maintain on different devices - share and edit with collaborators ```bash no more inconsistent state ``` **Focus** - strict version control helps you to work goal oriented ```bash no more chaotic changes ``` --- # Installing _git_ Download *git* for your operating system from [https://git-scm.com/downloads](https://git-scm.com/downloads)
--- class: center, middle # Local workflow with Command Line --- # Creating a local repository open your `Git-Bash` create a new directory ```bash mkdir mywebsite ``` change into that directory ```bash cd mywebsite ``` turn this folder into a git repository ```bash git init ``` --- # Checking your local repository you check the status of your repository using ```bash git status ``` which should give you ```bash On branch master No commits yet nothing to commit (create/copy files and use "git add" to track) ``` --- # Change something & commit it In your folder `mywebsite` create a file `helloworld.html` with the content ```html
Hello World!
``` check how git sees that file ```bash git status ``` which tells you that there are ```bash No commits yet Untracked files: (use "git add
..." to include in what will be committed) helloworld.html nothing added to commit but untracked files present (use "git add" to track) ``` --- # Change something & commit it so let's follow the advice and do ```bash git add helloworld.html ``` and then **commit** this change ```bash git commit -m 'add my first file' ``` you can always check everything you did with ```bash git log ``` ```bash commit 3b5616d1ba962e7a2e4af1f1bdd54f5d65d4e22d (HEAD -> master) Author: Oscan Openness
Date: Sun Jan 12 12:20:28 2020 +0100 --- class: center, middle # Remote workflow with Gitlab --- # Login to gitlab create an account (with switch edu) if you have none --- # Create a gitlab project (1/2)
--- # Create a gitlab project (2/2)
--- # Finish setup gitlab create a password in the settings add an SSH key (optional)
--- # Finish local setup
(skip the `git init`, `git add .` and `git commit -m "Initial commit` steps) --- # Add a readme explain your project for others and your future self
--- # Add a license everything you write has Copyright Copyright gives you exclusive rights (no one can use it without permission) use a license to define permissions for others MIT to allow usage without restrictions GPL to allow usage if basic freedom granted to users (many others)
--- class: center, middle # Github Desktop to simplify --- # Install github desktop download from https://desktop.github.com/ then open your repository folder
--- # Pull changes download the changes made on gitlab
--- # Commit changes change your local file then preview the changes and then commit
--- # Push changes push the changes
--- # View history see the changes you've made in the past
--- # Introduction done play around with it! we are here to answer questions. inspiration: - add some of your documents to git - change two files but only commit one - revert changes ressources: - https://education.github.com/git-cheat-sheet-education.pdf - https://git-scm.com/book/en/v2 in 30 Minutes we will start with advanced topics. --- # Advanced topics best-practices for commits create branch & merge request create issue & mention it in commit use SSH key fork & merge back into origin add different remotes --- # Best practices for commits - single purpose ```bash Improve best practice slide ``` - short, imperative subject line ```bash Add best practice slide ``` - tell why, not how ```bash Make wording on slides consistent ``` --- # Create branch & merge request - create branch ```bash git checkout -b new-branch ``` - push ```bash git push --set-upstream origin new-branch ``` - merge (on gitlab) --- # Create issue & mention it in commit - create issue on gitlab - commit local change with `#1` for `1` the issue number ```bash git commit -m "resolve #1" ``` - push - go to the issue on gitlab.com and observe --- # Use SSH key - create SSH key ```bash ssh-keygen -t rsa -b 4096 -C "florian.moser3@uzh.ch" && eval $(ssh-agent -s) && ssh-add ~/.ssh/id_rsa ``` - copy `~/.ssh/id_rsa.pub` - add the public key on gitlab.com - clone with SSH - try out push/pull to see it working