# Git workshop with SINTEF
This is a collaborative document for notes and questions
- Link to this document: https://hackmd.io/@coderefinery/git-sintef-2020
- Workshop page: https://coderefinery.github.io/2020-12-10-online/
- There is more material available than we will cover:
- https://coderefinery.github.io/git-intro/
- https://coderefinery.github.io/git-collaborative/
---
## Questions to get started
### Please describe (briefly) how you use Git or how you want to use Git if you haven't used it yet
- I use Git on a daily basis for own projects but also collaborative code projects. Mostly in combination with GitHub. Branching a lot. Mostly working within the same repository. Sometimes forking.
- Philippe. Using TortoiseGIT, mostly working on solo projects (no branching, merging...).
- Fabian: Quite new to git, use the basic tools. I'd llike to learn all the basics.
- Joachim: I use git, but only the very basic tools (add, commit, push, pull). I'd like to learn to branche, merge, fork etc.
- Samuel: Very new to GIT, never used it before
- Catalina: Very new to everything regarding codes, modelling, github etc:)
- Tina: Using mostly TortoiseGIT, have worked some with branching, but not familiar with advanced functionality
- Tuva: Also new to git, never used it.
- Miguel: basic git through a user-friendly interface (sourcetree) to work with common models and documents within the group.
### What would you like to get out of this course?
- Philippe. Learn to use GIT bash, as an alternative to Tortoise GIT. Better understand merging processes. Hear about strategies for the collaborative use of GIT and long term code management.
- Thor. Advanced use of git.
- Joachim Learn how to safely and efficiently branch, develope my code and merge.
- Samuel: Learn how GIT works
- Catalina: To understand how to manage/organize codes, and to work with people that write codes
- Fabian: HOw to branch, merge, and solve errors/conflicts when doing it.
- Miguel: create and maintain branches, clone, merge and understand other basic functions.
- Tuva: Learn how to use git.
- Tina: How to merge, and solve errors/conflicts when doing it, see how pull-requestes can be used
---
## Introduction
- Instructors introduce themselves
- Plan for today and tomorrow
- Zoom mechanics
- HackMD demo
- Why we start in the command line
- Then we go to Git
### Introduction round
Maybe you can write one line about yourself?
- [name=Radovan] working at UiT, background chemistry, teaching programming, also doing research software engineering
- [name=Philippe] SINTEF Industry, Materials & Nano. Numerical modeling, development of finite element methods.
- [name=Thor] SINTEF Industry, Sustainable Energy Technology. Software for modeling and visualisation of data.
- [name=Truls] Sustainable Energy Technology, Operations Research, support decision tool development
- [name=Samuel] SINTEF Industry, Metal Production and Processing, project management
- [name=Tina] SINTEF Industry, Sustainable Energy Technology, Industrial Economics and Operations Research. Decision support tools and some macroeconomic modelling
- [name=Catalina] Sintef Industry, Corrosion and tribology group. I am an electrochemist.
- [name=Joachim] SINTEF Materials Physics. I write code to run my scanning electron microscope and to analyse the images later.
- [name=Miguel] SINTEF Industry, Sustainable Energy Technology, Industrial Economics and Operations Research. Energy system analysis, feasibility studies.
- [name=Tuva] SINTEF Industry, Sustainable Energy Technology, Industrial Economics and Operations Research. Circular economy, sustainability assessments.
- [name=Fabian] SINTEF Industry, Sustainable Energy technology, industrial economics and operations research. Time series modeling, econometrics, environmental assessment.
- [name=Anne] CodeRefinery staff, working at the University of Oslo, department of Geosciences. Climate modelling & Open Science.
## Questions
- On windows, if you have CTRLF problem (warningss when adding files):
```
git config --global core.autocrlf false
```
- background: windows and git treat line endings a bit differently and with this we can tell Git what line ending convention to use
- After I did the config above, I get this error message:
```
$ git init - fatal: bad numeric config value 'false' for 'core.autocrlf': invalid unit
```
- there was a special character at the end
- I have a remote repo which is tracking some files (`__pycache__`). I'd like to add this to .gitignore. Will this remove it from my remote repo when pushing?
- I would first remove it with `git rm __pycache__`, then add it to `.gitignore`, then `git push`. Then it will also disappear on the remote.
- `git status` tells me if I have something in wd to add to (local) repo. I'd like to check if my local repo is up to date with my remote repo, i.e. will the remote repo add or change anything in my local repo if I do `git pull`? Is there such a command?
- we will clarify this tomorrow but git pull does modify your current branch in your local repo. tomorrow we will clarify the difference between git pull (which fetches changes and updates your current branch) and git fetch (which fetches changes but does not modify any local branch)
- in another words if you want to compare but not modify anything locally, do a `git fetch origin` and then you can compare with `git diff master origin/master` (assuming you are comparing the master branches)
- more about this tomorrow
- In git bash my default editor is vim. How do I change it to nano?
- `$ git config --global core.editor nano`
- see also https://coderefinery.github.io/installation/git/#configuring-git
- How much of a hash is needed for id in git show?
- 5-6-7 are enough. it only needs to be unique.
- How to undo merges commits?
- safe (meaning: not changing history): `git revert somehash` - this creates a new commit that applies the opposite of the reverted one
- you can also delete commits (by moving HEAD "back") with `git reset soft somehash` or `git reset hard somehash` - soft "removes" commits after `somehash` but keeps/stages changes, hard "recomves" commits and removes changes
- After merging a branch into master, what happens if I commit to that branch?
- then again that branch will move forward. i recommend to try it out and check with `git graph`. the branch will get one commit past the merge commit.
- How can I see which branches have been merged (and is no longer "active")?
- `git branch --merged` will list all branches that have been incorporated into current branch
- also git will complain if you try to `git branch --delete` it if it has not been merged into any other branch
- How can I see which branches are still "active", ie which branches have not been merged. Which branches are leaves?
- `git checkout master` followed by `git branch --no-merged`
- or I often look at the GitHub/GitLab network graphically :-)
### New questions Friday
- I have several repos. Git bash says I'm on branch master. How do I know which repo's master I'm on?
- `git rev-parse --show-toplevel`
- Commit messages can explain the idea behind a commit. Is there something similar for braches? A branch message to explain the idea behind a branch?
- Not that I know of, but will investigate today.
- What I do is to tag the branching off commit (https://git-scm.com/book/en/v2/Git-Basics-Tagging)
- Can I get a list of which files in a repo git is tracking? I'd like to check that I've written my`.gitignore` file corretly.
- `git ls-files`
- But this will be overwhelming when there are many files (sometime millions).
- So the opposite is recommended for the investigation.
- i.e. `git status` will not show the files that are ignored when modified
- Is it possible to create a remote repo (on github or bitbucket) from the command line?
- I found it is possible from [stackoverflow](https://stackoverflow.com/questions/2423777/is-it-possible-to-create-a-remote-repo-on-github-from-the-cli-without-opening-br)
- But it is better to do this through the web interface
- More documentation on github CLI: https://cli.github.com/
## Later: discussion about collaboration
This is preparation for tomorrow.
- how do you (plan to) collaborate?
- Group associated with a project working on a specific software
- For now, I'm the only one developing my code. Someone else is using it, and might contribute in the future.
- do your code projects have dedicated maintainers/roles?
- Normally not, all with read/write
- onboarding new staff? do you plan to have yearly courses?
- mentoring
- do you use pair programming?
- Seldom
## Feedback
- One thing that was good
- speed was good. Also the level of explainations
- the extra feedback on questions in Hackmd
- As you said, in the beginning it was a bit slow, but then the speed was good. Good idea to have the breakout room to get everyone on the same page.
- One thing to improve
- clarify the expected pre knowledge of the participants. Some are using git already, others have never seen a text terminal before.
- Maybe specify before the course that if you haven't used a text terminal before, it's important to go through the prep work. (I did, and if I hadn't I would have been quite lost.)
## We will start with publishing and cloning
https://coderefinery.github.io/git-intro/09-remotes/
### History inspection
https://coderefinery.github.io/git-intro/10-archaeology/
## Questions
- Please remind : how to delete a branch?
- https://coderefinery.github.io/git-intro/06-branches/#deleting-branches-safely
- locally: `git branch -d` or `git branch --delete`
- remotely: `git push origin --delete branchname`
- remotely via web: browse "branches" and recycle bin icon
## Exercise: history inspection
https://coderefinery.github.io/git-intro/10-archaeology/#exercise-basic-archaeology-commands
steps 1-5
optional extra exercise: git bisect
please also write here how it's going
on the last one (5), going through the solution
I've branched off at step 5
Finished bisect
## Break until 10:23
## Collaboration
https://coderefinery.github.io/git-collaborative/02-centralized/
Exercise preparation: https://coderefinery.github.io/git-collaborative/02-centralized/#exercise-preparation
I cloned the repo on Github, so I can (try to) be the admin. (Joachim: github / jmgpy)
## Break untile 11:16
Exercise: up to and including step 8 in https://coderefinery.github.io/git-collaborative/02-centralized/#exercise-description
Optional exercise: https://coderefinery.github.io/git-collaborative/02-centralized/#optional-exercise-or-demo-cross-referencing-issues
Please let us know how it is going
Tuva: I have created my pull request
Miguel: created pull request
## Feedback
Good course, I learned a lot! But it was definitely worth doing the prep work (even though I didn't do it all) before the course, since I had never used git or even bash before. Good speed on day 2. Also good discussions. I like that we keep access to the course material, as I expect I will need to refer back to it when I start using git actively. Thanks a lot!
I also enjoyed the course. I think having all participants setup before the meeting would have helped (with unified instructions on how to do so). Group excercise was enjoyable.
Excellent course.
---
Please write questions at the bottom of the document, above this line.