Tue Oct. 24
Version Control - GIT Workshop
9 – 12h Teaching
Teacher:
- Simon Eugster
- Diego Ballesteros Villamizar
Goals
Goals
- I understand the concept of Version Control and how to use it
- I can use Version Control software for my own projects and other Repos on GitHub (incl. Merge Requests)
- I know how to find more information about Version Control including
git help
- I know how to visualize differences between versions and how to undo changes
Important Things
Important Things
- No slides! You are lost.
- Or, take notes directly in a Git repository!
- Ask if something is unclear.
- We will use Git Bash! Command line does not change. GUIs will be obvious. (Fails the other way round)
- Servers usually only accessible through command line.
Intro
Intro
Why version control, and what is it?
- Take snapshots of code and upload them to a server
- Ever broke something and wanted to go back?
- Or, managed to fix a bug but forgot what you actually changed?
- Work together on the same code
Links
Links
- Explain Git with D3 mit dynamischen Grafiken
- Git Cheatsheet mit den 5 Bereichen in Git und Operationen darauf
- no deep shit
git help <command>
- Git Magic
Getting started: Clone a repository
Getting started: Clone a repository
- Clone https://github.com/power-coders/powercoders-002-git-workshop, see commits online
- Delete all files except for
.git
, restore withgit checkout -- .
(optionally when offline) - Examine
gitk
- Examine
.git/
First repository
First repository
init
init
Can be used completely offline.
- Create new repository in empty directory
- Examine
.git
and.git/objects/
again
git status, add, commit
git status, add, commit
Copy questions file from powercoders repository.
- Use
git status
and read the output after every operation. Command is new best friend. - Commit the file.
- Examine
.git/objects/
again
Accidentially delete questions file
- Check status and READ
- Revert
Check the logs
- Add something to “I want to remember”
- Commit
- Show git log in command line with
git log
and ingitk
- Find out how to show log on single line with
git help log
Theory
Git Areas
- Checkout / Workspace
- Staging Area / Index
- Local Repository
Commits
- Snapshot of every single file (go to
.git/objects/
) - Hash uniquely identifies commit.
- Has parent.
git diff
git diff
Diff between two arbitrary snapshots.
- Compare to
HEAD^
- Compare two commits by short hash
- Change file and show diff
- Stage file and show diff
Undo changes in staging area and workspace
- Change file, undo it
- Change file, stage it, undo it.
git branch
git branch
Create branch with new directory
- Create and checkout branch
- Examine in
gitk
andgit log --decorate
- Add directory
food
with filefavourite.md
, commit
Switch Branches
- Check out master branch, check files
- Add a new file
best-about-git.md
and commit it - Merge other branch into master
Theory
Branches
- Branch: Pointer in
.git/refs/heads/
- Why branches? Merge requests, add features.
master
remains stable. - Two commits have same parent. See D3 animation
git merge, rebase
git merge, rebase
Merge Conflict Scenario: Two people working on the same file
- Add favourite beverage on branch
feature/beverage
tofavourite.md
- Add favourite swiss food on
master
- Merge feature branch into master
- Resolve merge conflict
Rebasing a branch
- Same as before
- Go to feature branch and rebase it onto master
Theory
Rebase; show with D3
- Diff is always between two things. Hard with branches.
- Rebase avoids divergent branches
- Merge leaves commits unchanged
- Later:
pull
always with rebase
git stash, remote
git stash, remote
Stash changes and get them back
- Change something and stash it away
- Check
git status
,git log
,gitk --all
- Recover the stash with
git pop --index
Remotes
- Show remotes on cloned exercise repo and on local repository
- Create repository on GitHub
- Add repository as new remote
Theory
- Stash: New area, also saves snapshots, but only locally.
- Remotes: Repository on a server; server must accept connections. Examples: GitHub, GitLab, BitBucket, gitolite
12 – 13.30h Lunch
13.30 – 17h Coaching
Coaches:
Afternoon exercises
Afternoon exercises
- Push new repository to Github. Find out how to create SSH key.
- Also push the branches.
- Fork repository of someone else
- Submit merge request
- Fill in remaining questions/goals in exercise sheet
- Time per question. Answer questions if necessary.
- Work on same repository:
pull --rebase
- Push own web page