summerschool_simtech_2023/material/2_tue/git/git_basics_demo.md

4.1 KiB
Raw Blame History

Git Demo

Recap of Git basics

  • Expert level poll on git: ask students to estimate their level.
    • Beginner: I have hardly ever used Git
    • User: pull, commit, push, status, diff
    • Developer: fork, branch, merge, checkout
    • Maintainer: rebase, squash, cherry-pick, bisect
    • Owner: submodules
git overview picture from py-rse
  • git --help, git commit --help

  • incomplete statement git comm

  • There is a difference between Git and hosting services (forges)

  • Give outlook on remainder of Git chapter: How I work with Git, quiz, advanced topics (workflows, rebase, standards), my neat little Git trick

How I work with Git

Starting remarks:

  • There is not the one solution how to do things with Git. I simply show what I typically use.

  • Dont use a client if you dont understand the command line git

    1. Look at GitHub
    1. Working directory:
    • ZSH shell shows git branches
    • git remote -v (I have upstream, myfork, …)
    • mention difference between ssh and https (also see GitHub)
    • get newest changes git pull upstream develop
    • git log -> I use special format, see ~/.gitconfig,
    • check log on GitHub; explain short hash
    • git branch
    • git branch add-demo-feature
    • git checkout add-demo-feature
    1. First commit
    • git status -> always tells you what you can do
    • vi src/action/Action.hpp -> add #include "MagicHeader.hpp"
    • git diff, git diff src/com/Action.hpp, git diff --color-words
    • git status, git add, git status
    • git commit -> “Include MagicHeader in Action.hpp”
    • git status, git log, git log -p, git show
    1. Change or revert things
    • I forgot to add sth: git reset --soft HEAD~1, git status
    • git diff, git diff HEAD because already staged
    • git log
    • git commit
    • actually all that is nonsense: git reset --hard HEAD~1
    • modify again, all nonsense before committing: git checkout src/action/Action.hpp
    1. Stash
    • while working on unfinished feature, I need to change / test this other thing quickly, too lazy for commits / branches
    • git stash
    • git stash pop
    1. Create PR
    • create commit again
    • preview what will be in PR: git diff develop..add-demo-feature
    • git push -u myfork add-demo-feature -> copy link
    • explain PR template
    • explain target branch
    • explain “Allow edits by maintainers”
    • cancel
    • my fork -> branches -> delete
    1. Check out someone elses work
    • have a look at an existing PR, look at all tabs, show suggestion feature
    • but sometimes we want to really build and try sth out …
    • git remote -v
    • git remote add alex git@github.com:ajaust/precice.git if I dont have remote already (or somebody else)
    • git fetch alex
    • git checkout -t alex/[branch-name]
    • I could now also push to ajausts remote

Further reading

Quick things

References