diff --git a/.gitignore b/.gitignore index 96a2396..362c00b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ vm/*.ova vm/mnt trainer/ static/ +\#* +*~ \ No newline at end of file diff --git a/day1/00_Organisation/01_Intro.md b/day1/00_Organisation/01_Intro.md index 620d857..d927197 100644 --- a/day1/00_Organisation/01_Intro.md +++ b/day1/00_Organisation/01_Intro.md @@ -4,7 +4,7 @@ * Name and Company * Your role and or daily business -* Any previous experiences with git +* Any previous experiences with Git * Your expectations for this training !SLIDE subsection @@ -26,8 +26,6 @@ * WiFi is pre-configured * Exercises use the default terminal -* GitLab App from NWS - nws.netways.de, test account required - !SLIDE smbullets # BBB Application @@ -45,32 +43,3 @@ Click on the link in your email to join the session * Operating system is CentOS * We use tmux to join your session and help you * Change the appearance of the terminal as you like - - -~~~SECTION:handouts~~~ - -**** - - -~~~ENDSECTION~~~ - -!SLIDE smbullets -# Create GitLab app in NWS - -* Objective: - * Create a new GitLab app in NWS -* Steps: - * Navigate to https://nws.netways.de and register a trial account if not existing - * Choose Apps > GitLab CE > Basic - * Deploy the app - * Choose `Access` and `Live View` and set a secure password for the `root` user - * Login with `root` and your chosen password - * Wait for the trainer with the Git Basics - -~~~SECTION:handouts~~~ - -**** - - -~~~ENDSECTION~~~ - diff --git a/day1/01_Introduction/01_Intro.md b/day1/01_Introduction/01_Intro.md index 3d966c2..b2d67dd 100644 --- a/day1/01_Introduction/01_Intro.md +++ b/day1/01_Introduction/01_Intro.md @@ -2,13 +2,15 @@ # ~~~SECTION:MAJOR~~~ Git Introduction !SLIDE smbullets -# Version Control +# Why use Version Control Systems? -* Version Control System (VCS) -* Record changes of file(s) -* Revert changes -* Compare changes over time -* Who, when, what +* Version Control Systems (VCS) track changes over time +* They track who changed what and when +* Changes can be compared, reverted, coordinated with others + +Usually VCS are used for source code, text documents, web sites, or other text data. + +There are also data VCS for data science or machine learning projects. ~~~SECTION:handouts~~~ @@ -23,42 +25,187 @@ filesystem structure over time. Long time ago developers invented version control systems which store the file revisions in a database. - ~~~ENDSECTION~~~ +!SLIDE +# Centralized and Distributed VCS + +* Central VCS + * A central system contains the *version database*, clients work on this system + * Examples: CVS, Subversion +* Decentral VCS + * Clients mirror the *version database* from a central system and work locally + * Examples: Git, Mercurial + + + + + + + + +
Central VCS
Decentral VCS
+ +!SLIDE +# The History of Git + +Git was developed by the Linux kernel team in 2005. + +* They originally used BitKeeper, a closed-source commercial tool +* They created Git due to some controversy with BitKeeper + +Their design goals: + +* A fully distributed VCS +* Speed (when working with huge numbers of files) +* Simple design +* Non-linear development (branching) + +Git has become a de facto standard for version control. !SLIDE smbullets -# Centralized VCS +# The Git Workfow is local -* Multiple computers required file revisions -* CVS, Subversion -* What happens if the server is down? +In Git we `clone` the data to our local system and work locally. -
Central VCS
+* No network latency involved as with other VCS systems +* Faster operations due to the local data +* We can work offline and push changes later (i.e. when traveling) +!SLIDE smbullets +# Git Installation -~~~SECTION:handouts~~~ +The Git CLI is available for most operating systems. -**** +* Linux package are available in most distibutions +* Installers for macOS or Windows +* Many GUI clients are available +Optional shell integrations provide auto-completion and quality-of-life features. -~~~ENDSECTION~~~ +training@netways ~$ cd repository +training@netways ~/repository (feature/docs) $ !SLIDE smbullets -# Distributed VCS +# Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Install Git -* Clients mirror the repository -* Git, Mercurial, Bazaar, etc. -* Server dies, client continues +* Objective: + * Install the `git` package +* Steps: + * Use the package manager to install the git package -
Decentral VCS
+!SLIDE supplemental exercises +# Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Install Git -~~~SECTION:handouts~~~ +## Objective: Install the Git package +**** + +* Install the `git` package + +## Steps: **** +* Use the package manager to install the git package -~~~ENDSECTION~~~ +!SLIDE supplemental solutions +# Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Proposed Solution +**** + +## Install the Git package + +**** + +### Example for Debian/Ubuntu + + @@@ Sh + $ apt-get install git + +### Example for RHEL/CentOS + + @@@ Sh + $ yum install git + +### Example for Fedora + + @@@ Sh + $ dnf install git + +!SLIDE smbullets small +# Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Install Git Bash Integration + +* Objective: + * Install bash completion and Git status +* Steps: + * Use the package manager to install the `bash-completion` package + * Fetch the `git-prompt.sh` script from https://github.com/git/git - `contrib/completion/git-prompt.sh` + * Customize your prompt in your `$HOME/.bashrc` file + +Example: + + $ vim $HOME/.bashrc + source ~/git-prompt.sh + export GIT_PS1_SHOWDIRTYSTATE=1 + export PS1='[\u@\h] \W$(__git_ps1 " (%s)") \$ ' + + $ source $HOME/.bashrc + +!SLIDE supplemental exercises +# Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Install Git Bash Integration + +## Objective: Install the Git Bash Integration +**** + +* Install the `bash-completion` package +* Modify your prompt to highlight the git state + +## Steps: + +**** + +* Use the package manager to install the `bash-completion` package +* Fetch the `git-prompt.sh` script from https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh +* Customize your prompt +* Persist changes in your .bashrc file + +!SLIDE supplemental solutions +# Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Proposed Solution +**** + +## Install Git Bash Integration + +**** + +### Example for Debian/Ubuntu + + @@@ Sh + $ apt-get install bash-completion + +### Example for RHEL/CentOS + + @@@ Sh + $ yum install bash-completion + +### Example for Fedora + + @@@ Sh + $ dnf install bash-completion + +### Fetch the git-prompt.sh script + + @@@ Sh + $ wget https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh + +### Customize your prompt in your .bashrc file + +Additional configuration settings can be found +in the source code documentation at https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh#L38 + @@@ Sh + $ vim $HOME/.bashrc + source ~/git-prompt.sh + export GIT_PS1_SHOWDIRTYSTATE=1 + export PS1='[\u@\h] \W$(__git_ps1 " (%s)") \$ ' + $ source $HOME/.bashrc diff --git a/day1/01_Introduction/06_Gui_Clients.md b/day1/01_Introduction/02_Gui_Clients.md similarity index 88% rename from day1/01_Introduction/06_Gui_Clients.md rename to day1/01_Introduction/02_Gui_Clients.md index 05a4062..0ce7c9c 100644 --- a/day1/01_Introduction/06_Gui_Clients.md +++ b/day1/01_Introduction/02_Gui_Clients.md @@ -1,8 +1,9 @@ !SLIDE smbullets # Git GUI Clients -In this training, we are working with the CLI. For your work -environment, here are a few recommendations for GUI clients: +In this training, we will work with the command-line interface. + +These are a few recommendations for graphical clients: * Sourcetree (Windows, macOS) * GitKraken (Windows, Linux, macOS) @@ -15,9 +16,9 @@ environment, here are a few recommendations for GUI clients: **** Additional GUI clients can be found here: -https://git-scm.com/download/gui/linux -https://gitextensions.github.io/ +* https://git-scm.com/download/gui/linux +* https://gitextensions.github.io/ ~~~ENDSECTION~~~ @@ -74,4 +75,3 @@ Download: https://www.gitkraken.com/ Download: https://desktop.github.com/ ~~~ENDSECTION~~~ - diff --git a/day1/01_Introduction/02_History.md b/day1/01_Introduction/02_History.md deleted file mode 100644 index d6be7f5..0000000 --- a/day1/01_Introduction/02_History.md +++ /dev/null @@ -1,27 +0,0 @@ -!SLIDE smbullets -# History of Git - -* Linux kernel development - * Patches and archives - * Proprietary software `BitKeeper` -* Controversy in 2005, no more free to use -* Kernel developers invented `Git` - -!SLIDE smbullets -# Design Goals for Git - -* Speed -* Simple design -* Non-linear development (many branches) -* Fully distributed -* Handle large projects in speed and size - - -~~~SECTION:handouts~~~ - -**** - - -~~~ENDSECTION~~~ - - diff --git a/day1/01_Introduction/03_Basics.md b/day1/01_Introduction/03_Basics.md deleted file mode 100644 index dbbb6dd..0000000 --- a/day1/01_Introduction/03_Basics.md +++ /dev/null @@ -1,157 +0,0 @@ -!SLIDE smbullets -# When coming from another VCS - -* If you have knowledge about other VCS - try to put it aside -* A lot of commands sound similar but work differently in git - * A `git commit` is not the same as an `svn commit` - -~~~SECTION:handouts~~~ - -**** - - -~~~ENDSECTION~~~ - - -!SLIDE smbullets noprint -# Snapshots and Differences - -* File changes and deltas over time - * Git Commit, take snapshot, store reference to that snapshot - * Set of snapshots of a mini-filesystem - * No change - link to the previous identical stored file - -
Detla Changes
- -!SLIDE smbullets printonly -# Snapshots and Differences - -* File changes and deltas over time - * Git Commit, take snapshot, store reference to that snapshot - * Set of snapshots of a mini-filesystem - * No change - link to the previous identical stored file - -
Detla Changes
- - -!SLIDE smbullets noprint -# The three states - -* Working directory ("modified") -* Staging area ("staged") -* Git directory ("committed") - -
Git Stages
- -!SLIDE smbullets printonly -# The three states - -* Working directory ("modified") -* Staging area ("staged") -* Git directory ("committed") - -
Git Stages
- -~~~SECTION:notes~~~ - -`Modified` means that you have changed the file but have not committed -it to your Git database yet. - -`Staged` means that you have marked a modified or added file in its -current version to go into your next commit snapshot. - -`Committed` means that the data is safely stored in your local database. - -The `working directory` is a single checkout of one version of the project. -These files are pulled out of the compressed database in the Git directory -and placed on disk for you to use or modify. - -The `staging area` is a file, generally located in your Git directory, that -stores information about what will go into your next commit. -It is sometimes referred to as the "index", but it’s also common to refer -to it as the staging area. - -The `Git directory` is where Git stores the metadata and object database -for your project. This is the most important part of Git, and it is what -is copied when you clone a repository from another computer. - - -~~~ENDSECTION~~~ - -~~~SECTION:handouts~~~ - -**** - - -`Modified` means that you have changed the file but have not committed -it to your Git database yet. - -`Staged` means that you have marked a modified or added file in its -current version to go into your next commit snapshot. - -`Committed` means that the data is safely stored in your local database. - -The `working directory` is a single checkout of one version of the project. -These files are pulled out of the compressed database in the Git directory -and placed on disk for you to use or modify. - -The `staging area` is a file, generally located in your Git directory, that -stores information about what will go into your next commit. -It is sometimes referred to as the "index", but it’s also common to refer -to it as the staging area. - -The `Git directory` is where Git stores the metadata and object database -for your project. This is the most important part of Git, and it is what -is copied when you clone a repository from another computer. - -~~~ENDSECTION~~~ - -!SLIDE smbullets -# Basic Git Workflow - -* Modify files in `working directory` -* Stage the files which add snapshots to the `staging area` ("git add") -* Commit ("git commit") - * Takes files from `staging area` - * Stores snapshot permanently in `.git directory` - -~~~SECTION:handouts~~~ - -**** - -* If a particular version of a file is in the `.git directory`, it’s considered `committed` - -* `Staged` means that the file has been modified and it was added to the staging area - -* `Modified` means that the file was changed since it was checked out but has not been staged yet - -~~~ENDSECTION~~~ - - -!SLIDE smbullets -# The Git Workfow is local - -* No network latency involved as with other VCS systems -* Local repository clone, fast operations - * Browse the history - * Show differences between specific branches -* Work offline and push changes later - -!SLIDE smbullets -# Git Object Integrity - -* Everything has a checksum (SHA) -* No changes possible without Git knowing about them -* Checksums are used everywhere -* Revert changes and even restore deleted files - -Example: - - 7f0b824ba55e1fd4ffc5c461df0a0f48a94195cc - -~~~SECTION:handouts~~~ - -**** - - -~~~ENDSECTION~~~ diff --git a/day1/02_Configuration/02_Global.md b/day1/01_Introduction/03_Configuration.md similarity index 68% rename from day1/02_Configuration/02_Global.md rename to day1/01_Introduction/03_Configuration.md index 55554dd..c986bdb 100644 --- a/day1/02_Configuration/02_Global.md +++ b/day1/01_Introduction/03_Configuration.md @@ -1,49 +1,45 @@ !SLIDE smbullets -# Configuration +# Git Configuration -* CLI command support -* Edit $HOME/.gitconfig directly - -Example: - - @@@ Sh - $ git config --global user.email michael.friedrich@netways.de - - $ cat $HOME/.gitconfig - [user] - email = michael.friedrich@netways.de +The Git command-line can be configured in multiple locations: +* Global for the user + * `$HOME/.gitconfig` +* Local to the repository + * `training/.git/config` -~~~SECTION:handouts~~~ +Optional configuration can also be included: -**** - -More information can be found in the documentation at -https://git-scm.com/book/tr/v2/Customizing-Git-Git-Configuration + [includeIf "gitdir:/path/to/group/"] + path = /path/to/foo.inc ~~~ENDSECTION~~~ !SLIDE smbullets -# Configuration Sections +# Git Configuration Sections + +The Git configuration has different sections. -* Commit author (`user`) -* Aliases (`alias`) -* Colors for diff and verbose commit (`color`) -* Core functionality (`core`) +* Commit author [`user`] +* Core functionality (e.g. editor, pager) [`core`] +* Colors [`color`] and Aliases [`alias`] +* And many more... Example: @@@ Sh [user] - email = michael.friedrich@netways.de - name = Michael Friedrich - [color "status"] - untracked = red + email = name.surname@example.com + name = Name Surname + [core] + editor = nano ~~~SECTION:handouts~~~ **** +More information can be found in the documentation at +https://git-scm.com/book/tr/v2/Customizing-Git-Git-Configuration ~~~ENDSECTION~~~ @@ -87,12 +83,12 @@ Example: ### Set the global username @@@ Sh - $ git config --global user.name "Michael Friedrich" + $ git config --global user.name "Name Surname" ### Set the global email address @@@ Sh - $ git config --global user.email "michael.friedrich@netways.de" + $ git config --global user.email "name.surname@example.com" ### Verification @@ -106,4 +102,3 @@ In addition to that you can open the `.gitconfig` file in your $HOME directory. ### Notes You can also use `git config --global --list` to list all configured options. - diff --git a/day1/01_Introduction/04_Basics.md b/day1/01_Introduction/04_Basics.md new file mode 100644 index 0000000..ab615f2 --- /dev/null +++ b/day1/01_Introduction/04_Basics.md @@ -0,0 +1,89 @@ +!SLIDE smbullets +# Core Concepts of Git + +* All work is done in a **repository**, it contains our files +* Snapshots track changes in these file, these are called **commits** +* A chain of these commits is called a **branch** + +Analogy: Writing on a desk or packing a parcel. + +!SLIDE smbullets +# Git Commit + +A Commit is a snapshot in time, containing: an author, a timestamp and the current state of the files. + +Git stores compressed snapshots (aka BLOBs) of the files, not diffs. It keeps track of changes with checksums (SHA) of these BLOBs. + +If a file does not change between commits, Git just refers back to the previous commit. + +
Git Snapshots
+ +!SLIDE smbullets +# Git Branch + +Since each commit has a pointer to the commit directly before it (its parent), they form a chain (or linked list). + +This chain is called a branch. + +Branches represent an isolated line of development. + +
Feature Branch Workflow
+ +!SLIDE +# The Three States + +Files in a repository go through three states before being version controlled. + +* Working directory ("modified") +* Staging area ("staged") +* Git directory ("committed") + +
Git Stages
+ +~~~SECTION:handouts~~~ + +**** + +`Modified` means that you have changed the file but have not committed +it to your Git database yet. + +`Staged` means that you have marked a modified or added file in its +current version to go into your next commit snapshot. + +`Committed` means that the data is safely stored in your local database. + +The `working directory` is a single checkout of one version of the project. +These files are pulled out of the compressed database in the Git directory +and placed on disk for you to use or modify. + +The `staging area` is a file, generally located in your Git directory, that +stores information about what will go into your next commit. +It is sometimes referred to as the "index", but it’s also common to refer +to it as the staging area. + +The `Git directory` is where Git stores the metadata and object database +for your project. This is the most important part of Git, and it is what +is copied when you clone a repository from another computer. + +~~~ENDSECTION~~~ + +!SLIDE smbullets +# The Git Commit Workflow + +* Modify files in the `working directory` +* Stage the files in the `staging area` ("git add") to prepare a commit +* Create a snapshot ("git commit") + * Takes all files from the `staging area` + * Stores the snapshot permanently in the `.git directory` + +~~~SECTION:handouts~~~ + +**** + +* If a particular version of a file is in the `.git directory`, it’s considered `committed` + +* `Staged` means that the file has been modified and it was added to the staging area + +* `Modified` means that the file was changed since it was checked out but has not been staged yet + +~~~ENDSECTION~~~ diff --git a/day1/01_Introduction/04_Cli.md b/day1/01_Introduction/04_Cli.md deleted file mode 100644 index f89c84d..0000000 --- a/day1/01_Introduction/04_Cli.md +++ /dev/null @@ -1,15 +0,0 @@ -!SLIDE smbullets -# Git CLI - -* Work on the CLI -* GUIs implement partial feature sets of the CLI tool -* Shell sub commands -* Bash-completion - - -~~~SECTION:handouts~~~ - -**** - - -~~~ENDSECTION~~~ diff --git a/day1/01_Introduction/05_Installation.md b/day1/01_Introduction/05_Installation.md deleted file mode 100644 index bd77769..0000000 --- a/day1/01_Introduction/05_Installation.md +++ /dev/null @@ -1,303 +0,0 @@ -!SLIDE smbullets noprint -# Git Installation - -* Available as package -* macOS, Windows installers -* Bash Integration - * Completion - * Show status and branch in the terminal - -Example: - -training@netways ~$ cd repository - -training@netways ~/repository (feature/docs) $ - -!SLIDE smbullets printonly -# Git Installation - -* Available as package -* macOS, Windows installers -* Bash Integration - * Completion - * Show status and branch in the terminal - -Example: - -training@netways ~$ cd repository - -training@netways ~/repository (feature/docs) $ - - -~~~SECTION:handouts~~~ - -**** - - -~~~ENDSECTION~~~ - - -!SLIDE smbullets -# Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Install Git - -* Objective: - * Install the `git` package -* Steps: - * Use the package manager to install the git package - -~~~SECTION:handouts~~~ - -**** - -~~~ENDSECTION~~~ - -!SLIDE supplemental exercises -# Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Install Git - -## Objective: Install the Git package -**** - -* Install the `git` package - -## Steps: - -**** - -* Use the package manager to install the git package - -!SLIDE supplemental solutions -# Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Proposed Solution -**** - -## Install the Git package - -**** - -### Example for Debian/Ubuntu - - @@@ Sh - $ apt-get install git - -### Example for RHEL/CentOS - - @@@ Sh - $ yum install git - -### Example for Fedora - - @@@ Sh - $ dnf install git - -!SLIDE smbullets small -# Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Install Git Bash Integration - -* Objective: - * Install bash completion and Git status -* Steps: - * Use the package manager to install the `bash-completion` package - * Fetch the `git-prompt.sh` script from https://github.com/git/git - `contrib/completion/git-prompt.sh` - * Customize your prompt in your `$HOME/.bashrc` file - -Example: - - $ vim $HOME/.bashrc - source ~/git-prompt.sh - export GIT_PS1_SHOWDIRTYSTATE=1 - export PS1='[\u@\h] \W$(__git_ps1 " (%s)") \$ ' - - $ source $HOME/.bashrc - - -~~~SECTION:notes~~~ - - -~~~ENDSECTION~~~ - -~~~SECTION:handouts~~~ - -**** - -The training notebooks come pre-provisioned with this `.bashrc` configuration: - - @@@ Sh - vim $HOME/.bashrc - - # Enable Git branch and modifications in colored terminal - # - # Adopted from Michael Friedrich's dev environment. - - # requires git bash completion - source /etc/bash_completion.d/git - # CentOS 7 specific (!) - source /usr/share/git-core/contrib/completion/git-prompt.sh - - # global options - export GIT_PS1_SHOWDIRTYSTATE=1 - #export GIT_PS1_SHOWSTASHSTATE='y' - #export GIT_PS1_SHOWUNTRACKEDFILES='y' - #export GIT_PS1_DESCRIBE_STYLE='contains' - export GIT_PS1_SHOWUPSTREAM='git' - - function myPrompt() { - local GREEN_BOLD="\[\033[01;32m\]" - local RED_BOLD="\[\033[01;31m\]" - local BLUE_BOLD="\[\033[01;34m\]" - local GREEND="\[\033[02;32m\]" - local REDD="\[\033[02;32m\]" - local DEFAULT="\[\033[00m\]" - - # \h ... hostname - # \w ... workdir - # \$? ... RC - # \u ... user - # \$(formattedGitBranch) ... git branch if available - - local USER_BOLD=$GREEN_BOLD - local USERD=$GREEND - local USERAT="\u@\h" - local USERHASH="\$" - - if [ `/usr/bin/whoami` = 'root' ] - then - USER_BOLD=$RED_BOLD - USERD=$REDD - USERAT="\h" - USERHASH="#" - fi - - PS1="$USER_BOLD$USERAT$DEFAULT $BLUE_BOLD\w$DEFAULT" - PS1=$PS1"$DEFAULT$GREEND\$(__git_ps1)$BLUE_BOLD $USERHASH $DEFAULT" - - # window title - case "$TERM" in - xterm*|rxvt*) - PS1="\[\e]0;\h: \w (\u)\a\]$PS1" - ;; - esac - } - -~~~ENDSECTION~~~ - -!SLIDE supplemental exercises -# Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Install Git Bash Integration - -## Objective: Install the Git Bash Integration -**** - -* Install the `bash-completion` package -* Modify your prompt to highlight the git state - -## Steps: - -**** - -* Use the package manager to install the `bash-completion` package -* Fetch the `git-prompt.sh` script from https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh -* Customize your prompt -* Persist changes in your .bashrc file - - -!SLIDE supplemental solutions -# Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Proposed Solution -**** - -## Install Git Bash Integration - -**** - -### Example for Debian/Ubuntu - - @@@ Sh - $ apt-get install bash-completion - -### Example for RHEL/CentOS - - @@@ Sh - $ yum install bash-completion - -### Example for Fedora - - @@@ Sh - $ dnf install bash-completion - -### Fetch the git-prompt.sh script - - @@@ Sh - $ wget https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh - -### Customize your prompt in your .bashrc file - -Additional configuration settings can be found -in the source code documentation at https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh#L38 - - @@@ Sh - $ vim $HOME/.bashrc - source ~/git-prompt.sh - export GIT_PS1_SHOWDIRTYSTATE=1 - export PS1='[\u@\h] \W$(__git_ps1 " (%s)") \$ ' - - $ source $HOME/.bashrc - - -!SLIDE smbullets noprint -# More Git Shell Integrations - -Powerline Shell - -Powerline Shell Integration - -Windows Powershell: git-posh - -Powershell Integration - -!SLIDE smbullets printonly -# More Git Shell Integrations - -Powerline Shell - -Powerline Shell Integration - -Windows Powershell: git-posh - -Powershell Integration - -~~~SECTION:handouts~~~ - -**** - -### Powerline Shell Integration - -The Powerline shell integration can be found here: https://github.com/b-ryan/powerline-shell - - @@@ Sh - # yum -y install epel-release - # yum -y install python-pip - # pip install powerline-shell - - @@@ Sh - $ vim $HOME/.bashrc - - function _update_ps1() { - PS1=$(powerline-shell $?) - } - - if [[ $TERM != linux && ! $PROMPT_COMMAND =~ _update_ps1 ]]; then - PROMPT_COMMAND="_update_ps1; $PROMPT_COMMAND" - fi - -Powerline needs an additional font which can be downloaded from here: -https://github.com/powerline/fonts/blob/master/Meslo%20Slashed/Meslo%20LG%20M%20Regular%20for%20Powerline.ttf - -Choose `Raw` and install it into your system. - -Modify your terminal profile settings and choose `Meslo LG` as font. - -### Windows Powershell Integration - -The Windows Powershell integration requires NuGet. Open a new Powershell prompt and enter: - - @@@ Sh - Install-Module git-posh - Add-PoshGitToProfile - -~~~ENDSECTION~~~ diff --git a/day1/02_Configuration/01_Intro.md b/day1/02_Configuration/01_Intro.md deleted file mode 100644 index 205d38e..0000000 --- a/day1/02_Configuration/01_Intro.md +++ /dev/null @@ -1,19 +0,0 @@ -!SLIDE subsection -# ~~~SECTION:MAJOR~~~ Git Configuration - -!SLIDE smbullets -# Configuration Overview - -* Global configuration for the user - * `$HOME/.gitconfig` -* Local to the repository - * `training/.git/config` - - -~~~SECTION:handouts~~~ - -**** - - -~~~ENDSECTION~~~ - diff --git a/day1/03_Basics/01_Intro.md b/day1/03_Basics/01_Intro.md index c96d8fa..9a595bf 100644 --- a/day1/03_Basics/01_Intro.md +++ b/day1/03_Basics/01_Intro.md @@ -19,20 +19,20 @@ Example from Git CLI command: start a working area (see also: git help tutorial) clone Clone a repository into a new directory init Create an empty Git repository or reinitialize an existing one - + work on the current change (see also: git help everyday) add Add file contents to the index mv Move or rename a file, a directory, or a symlink rm --cached Reset current HEAD to the specified state rm Remove files from the working tree and from the index - + examine the history and state (see also: git help revisions) bisect Use binary search to find the commit that introduced a bug grep Print lines matching a pattern log Show commit logs show Show various types of objects status Show the working tree status - + grow, mark and tweak your common history branch List, create, or delete branches checkout Switch branches or restore working tree files @@ -41,11 +41,10 @@ Example from Git CLI command: merge Join two or more development histories together rebase Forward-port local commits to the updated upstream head tag Create, list, delete or verify a tag object signed with GPG - + collaborate (see also: git help workflows) fetch Download objects and refs from another repository pull Fetch from and integrate with another repository or a local branch push Update remote refs along with associated objects - ~~~ENDSECTION~~~ diff --git a/day1/03_Basics/02_Start.md b/day1/03_Basics/02_Start.md index aa474c7..a5795b5 100644 --- a/day1/03_Basics/02_Start.md +++ b/day1/03_Basics/02_Start.md @@ -2,10 +2,10 @@ # Start a project * `git clone` - * Clone a copy of existing remote repository - * Can be newly created in GitLab/GitHub and empty + * Clones a copy of existing remote repository (i.e. from GitLab) + * Can be modified with `--depth=5` * `git init` - * Initialize a local empty Git repository + * Initializes a local empty Git repository ~~~SECTION:handouts~~~ @@ -22,7 +22,6 @@ called an `origin`. ~~~ENDSECTION~~~ - !SLIDE smbullets # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Clone an existing Git repository @@ -34,12 +33,6 @@ called an `origin`. * Navigate into your home directory * Use `git clone` to clone the remote Git repository -~~~SECTION:handouts~~~ - -**** - -~~~ENDSECTION~~~ - !SLIDE supplemental exercises # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Clone an existing Git repository @@ -57,8 +50,6 @@ called an `origin`. * Navigate into your home directory * Use `git clone` to clone the remote Git repository - - !SLIDE supplemental solutions # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Proposed Solution **** @@ -73,27 +64,17 @@ called an `origin`. $ cd $HOME $ git clone https://github.com/Icinga/icinga2.git - - !SLIDE smbullets # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Initialize a local Git repository * Objective: - * Initialize git repository + * Initialize a new Git repository * Steps: * Create a new directory called `training` in your home directory * Change into it * Run `git init` -We will be working inside the `training` directory throughout the training -unless noted otherwise. - - -~~~SECTION:handouts~~~ - -**** - -~~~ENDSECTION~~~ +We will be working inside this `training` directory unless noted otherwise. !SLIDE supplemental exercises # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Initialize a local Git repository @@ -111,8 +92,6 @@ unless noted otherwise. * Change into it * Run `git init` - - !SLIDE supplemental solutions # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Proposed Solution **** @@ -128,4 +107,3 @@ unless noted otherwise. $ mkdir training $ cd training $ git init - diff --git a/day1/03_Basics/03_Changes.md b/day1/03_Basics/03_Changes.md index e73914e..52f342e 100644 --- a/day1/03_Basics/03_Changes.md +++ b/day1/03_Basics/03_Changes.md @@ -2,11 +2,11 @@ # Add current changes * `git add` - * Add new files to Git (staged) - * Add modified file(s) from the working directory into the staging area + * Adds new files from the working directory to the staging area + * Adds modified files to the staging area * `-A` adds all files. Question: Where is this applicable? * `git mv` - * Rename file(s) tracked by Git + * Renames files tracked by Git ~~~SECTION:handouts~~~ @@ -25,8 +25,7 @@ manually move the file, you will need to rm and add it again. ~~~ENDSECTION~~~ - -!SLIDE smbullets small +!SLIDE smbullets # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Add a new README.md file * Objective: @@ -34,21 +33,13 @@ manually move the file, you will need to rm and add it again. * Steps: * Change into `$HOME/training` * Create README.md and add `# GitLab Training Notes` as first line - * Use `git add` to add README.md to the current change area + * Hint: You can keep notes from the training in the `README.md` file + * Use `git add` to add README.md to the staging area * Next steps: * Verify the change with `git status` -Best practice is to have a README.md file written in Markdown -in every project. This gets rendered by GitHub/GitLab in readable HTML. - -During this training we will learn many new things. Keep notes -in the `README.md` file. - -~~~SECTION:handouts~~~ - -**** - -~~~ENDSECTION~~~ +Markdown is a markup language that is rendered by GitLab as HTML. +Best practice is to have a README.md file written in Markdown in every project, which is great for documentation. !SLIDE supplemental exercises # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Add a new README.md file @@ -86,16 +77,15 @@ in the `README.md` file. ~~~ENDSECTION~~~ - !SLIDE smbullets # Remove changes * `git rm --cached` - * Reset files added to the staging area + * Removes files from to the staging area * Hint: This comes in handy with `git add -A` before * `git rm` - * Remove the file(s) from working tree and Git repository - * Note that file(s) will be visible in Git history, and can be restored from it + * Removes the files from working tree and Git repository + * Note: Once committed, files will be visible in the Git history, and can be restored from it ~~~SECTION:handouts~~~ @@ -111,24 +101,16 @@ and then selectively unstage the unwanted 5 changes. ~~~ENDSECTION~~~ - - !SLIDE smbullets # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Reset File from Staging Area * Objective: - * Reset file from staging area + * Remove a file from staging area * Steps: * Change into `$HOME/training` - * Remove the previously added `README.md` file from the staging area with `git rm --cached README.md` + * Remove the previously added README.md file from the staging area with `git rm --cached README.md` * Verify it with `git status` and explain what happened - * Re-add the `README.md` and examine again with `git status` - -~~~SECTION:handouts~~~ - -**** - -~~~ENDSECTION~~~ + * Re-add the README.md and examine again with `git status` !SLIDE supplemental exercises # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Reset File from Staging Area @@ -136,8 +118,7 @@ and then selectively unstage the unwanted 5 changes. ## Objective: Reset File from Staging Area **** -* Reset file from staging area - +* Remove a file from staging area ## Steps: @@ -170,4 +151,3 @@ and then selectively unstage the unwanted 5 changes. $ git add README.md $ git status - diff --git a/day1/03_Basics/04_Status.md b/day1/03_Basics/04_Status.md index 8ed2c4d..774ffe8 100644 --- a/day1/03_Basics/04_Status.md +++ b/day1/03_Basics/04_Status.md @@ -2,23 +2,20 @@ # Examine the current state * `git status` - * Show current working tree status - * Modified files - * Modified and added to staging for commit - * Untracked files - -Later we will learn how to compare specific commits and branches too + * Shows current working tree status + * Shows modified files and untracked files + * Shows what is in the staging area + * `--short` can be used for less output ~~~SECTION:handouts~~~ **** -`git status` shows the current working tree status. Untracked files and changes (not) staged -for commit +`git status` shows the current working tree status. +Untracked files and changes (not) staged for a commit. ~~~ENDSECTION~~~ - !SLIDE smbullets # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Examine current changes @@ -26,17 +23,11 @@ for commit * Examine current changes * Steps: * Change into `$HOME/training` - * Edit README.md and add notes + * Edit README.md and add more text * Use `git status` to see unstaged changes * Add the changed files to the staging area * Use `git status` again -~~~SECTION:handouts~~~ - -**** - -~~~ENDSECTION~~~ - !SLIDE supplemental exercises # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Examine current changes @@ -100,22 +91,19 @@ You'll recognize the unstaged changes compared to your staging area. # Examine the current state: Diff * `git diff` - * Compare changes between modified working tree and latest commit - * Output is a unified diff similar to `diff -ur file1 file2` + * Compares changes between modified working tree and latest commit + * The output is a unified diff similar to `diff -ur file1 file2` -Later we will learn how to compare specific commits and branches too. +Later we will learn how to compare other objects (i.e. commits and branches). ~~~SECTION:handouts~~~ **** -`git diff` shows changes between the current working tree and the last commit. You can -also compare specific commits +`git diff` shows changes between the current working tree and the last commit. You can also compare specific commits. ~~~ENDSECTION~~~ - - !SLIDE smbullets # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Use Git Diff @@ -129,12 +117,6 @@ also compare specific commits * Use `git diff` again * Explain what `git diff --staged` does -~~~SECTION:handouts~~~ - -**** - -~~~ENDSECTION~~~ - !SLIDE supplemental exercises # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Use Git Diff @@ -152,7 +134,6 @@ also compare specific commits * Use `git diff` again * Explain what `git diff --staged` does - !SLIDE supplemental solutions # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Proposed Solution **** diff --git a/day1/03_Basics/05_Gitignore.md b/day1/03_Basics/05_Gitignore.md index 97c0b28..463057f 100644 --- a/day1/03_Basics/05_Gitignore.md +++ b/day1/03_Basics/05_Gitignore.md @@ -1,19 +1,21 @@ -!SLIDE smbullets +!SLIDE # Exclude files with .gitignore -* Build directories from source code compilation (e.g. `debug/`, `release/`) +The `.gitignore` file can be used to ignore files from being tracked by Git. Each line specifies a pattern to ignore. The file is read from top to bottom. + +* Build directories for compilation (e.g. `debug/`, `release/`) * Files generated at runtime (e.g. test results or stats) * Temporary files (e.g. `*.tmp`, `temp/`) -* User specific IDE settings +* User specific settings or secrets Example: cat .gitignore release/ *.tmp - .idea + .env -Personal ignore patterns can be defined in `.git/info/exclude` +Personal ignore patterns can be defined in `.git/info/exclude`. ~~~SECTION:handouts~~~ @@ -36,12 +38,11 @@ and not a global file, this will also work ~~~ENDSECTION~~~ - !SLIDE smbullets # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Add .gitignore file and exclude files/directories * Objective: - * Add .gitignore file and exclude files/directories + * Add a .gitignore file and exclude files/directories * Steps: * Change into `$HOME/training` * Create a file `generated.tmp` @@ -50,12 +51,6 @@ and not a global file, this will also work * Exclude them in a .gitignore file * Examine the state with `git status` -~~~SECTION:handouts~~~ - -**** - -~~~ENDSECTION~~~ - !SLIDE supplemental exercises # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Add .gitignore file and exclude files/directories @@ -98,10 +93,10 @@ for simulating unwanted files in the working directory. @@@ Sh $ git status On branch main - + Untracked files: (use "git add ..." to include in what will be committed) - + debug/ generated.tmp @@ -121,13 +116,12 @@ trailing slash). @@@ Sh $ git status On branch main - + Untracked files: (use "git add ..." to include in what will be committed) - + .gitignore We'll learn how to add and commit the untracked `.gitignore` file in later examples. - diff --git a/day1/04_Commits/01_Intro.md b/day1/04_Commits/01_Intro.md index f1bed3e..32081da 100644 --- a/day1/04_Commits/01_Intro.md +++ b/day1/04_Commits/01_Intro.md @@ -1,19 +1,21 @@ !SLIDE subsection # ~~~SECTION:MAJOR~~~ Git Commits -!SLIDE smbullets +!SLIDE # Git Commits -* View as history log on production changes -* Keep the subject short, simple and explaining -* Make it easier for others understanding the changes -* Add detailed explanations on larger changes -* Add references to existing commits and/or ticket ids for further details +Commits are the history or logbook of our project. -~~~SECTION:handouts~~~ +* They can have a subject line and a body +* Keep the subject short and simple +* Add a detailed explanations for larger changes -**** +Example: + commit 25037b + Author: Anita Bath ` -* Enable the verbose mode `-v` to show the differences below the editor - * Write a short summary based on the visible changes +Make it easy for you and others to understand the changes over time. -~~~SECTION:handouts~~~ +* Selectively add changes for a commit (do not commit everything) +* Write a short summary based on the changes (what and why) +* You can add references to existing commits or ticket ids -**** +Over time, commits should tell a story of the history +of your repository and how it came to be the way that it currently is. +!SLIDE +# Good Commits Messages -~~~ENDSECTION~~~ - -!SLIDE smbullets -# Commit Message Overview - -* Pick a short telling subject (max. 80-120 characters) -* Add a new line -* Add a body text explaining the issue (max. 80-120 characters in a line) -* Optional: Add external reference markers, e.g. for ticket systems +* The subject line is the most important +* Describe why a change is being made in the body +* Do not assume the reviewer understands what the original problem was +* Do not assume the code is self-evident Example: - A short subject for the commit line - - Some body text explaining the issue. - 80-120 characters max width. - - refs # - -~~~SECTION:handouts~~~ - -**** - - -~~~ENDSECTION~~~ + Improve UI acessibility + Previously we had red and green buttons. + This made them difficult to differenciate + for colourblind people. + We are now using blue and purple. + + fixes #1 diff --git a/day1/04_Commits/04_History.md b/day1/04_Commits/04_History.md index 5620567..cc2e72f 100644 --- a/day1/04_Commits/04_History.md +++ b/day1/04_Commits/04_History.md @@ -2,20 +2,21 @@ # Examine the Git history * `git log` - * Show commit history of the current branch + * Shows the commit history of the current branch * Supports `-10` notation to show a limited number of commits + * `--oneline` can be used for less output * `git blame ` - * Show authors of a certain file line-by-line + * Shows the authors of a file line-by-line * Supports `--color-lines` notation for grouping lines of the same commit ~~~SECTION:handouts~~~ **** -`git log` shows the commit history of the current branch -`git blame `shows the author line-by-line of the selected file +`git log` shows the commit history of the current branch. +`git blame ` shows the author line-by-line of the selected file. ~~~ENDSECTION~~~ @@ -23,13 +24,13 @@ # Examine the Git history * `git show` - * Print commit details - * If the commit id is omitted, the last commit is printed + * Prints details of the latest commit + * Commit IDs can be used to show a specific commit * Supports `-10` notation to show a limited number of commits * `git diff` * Show changes between working tree and last commit * Supports source and target parameters - * Can be used to compare 2 commit ids, branches, etc. + * Can be used to compare commits, branches, etc. ~~~SECTION:handouts~~~ @@ -58,12 +59,6 @@ also compare specific commits. Bonus: Try `git log` with the `--graph` and `--oneline` option. -~~~SECTION:handouts~~~ - -**** - -~~~ENDSECTION~~~ - !SLIDE supplemental exercises # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Examine the Commit History @@ -141,12 +136,6 @@ Bonus: Try `git log` with the `--graph` and `--oneline` option.
Tig
-~~~SECTION:handouts~~~ - -**** - -~~~ENDSECTION~~~ - !SLIDE smbullets # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Learn more about tig @@ -160,12 +149,6 @@ Bonus: Try `git log` with the `--graph` and `--oneline` option. * Select a line and press `Enter` * `q` quits the detail view and the application -~~~SECTION:handouts~~~ - -**** - -~~~ENDSECTION~~~ - !SLIDE supplemental exercises # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Learn more about tig diff --git a/day1/04_Commits/05_Amend.md b/day1/04_Commits/05_Amend.md index a431ac9..f2ea065 100644 --- a/day1/04_Commits/05_Amend.md +++ b/day1/04_Commits/05_Amend.md @@ -1,22 +1,23 @@ !SLIDE smbullets # Amend changes to commits -* Change the commit message, e.g. typos or missing changes broke the build -* Amend changes from staging area -* Helps if new files were added but not committed -* `git commit --amend` changes the latest commit - * Amending commits in Git history is possible, explained later with `git rebase` +`git commit --amend` is a convenient way to modify the most recent commit. -If you amend changes to a specific commit, a new unique commit id is generated. -This changes the Git history and we will learn later how to resolve possible -problems in collaboration with others. +* Change the commit message (e.g. typos or better phrasing) +* Fix a bug in already commited files +* Add missing files into the last commit + +If you amend changes to a specific commit, a new unique commit ID is generated. + +This changes the Git history and we will learn later this might cause issues when collaborating. ~~~SECTION:handouts~~~ **** -~~~ENDSECTION~~~ +Amending other commits in Git history is also possible, explained later with `git rebase`. +~~~ENDSECTION~~~ !SLIDE smbullets # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Amend changes to commits @@ -25,19 +26,12 @@ problems in collaboration with others. * Use git amend * Steps: * Change into `$HOME/training` - * Modify `README.md` and add docs about amend - * Add `README.md` to the staging area and commit the change - * Edit `README.md` again and add it to staging area + * Modify README.md and add more text + * Add README.md to the staging area and commit the change + * Edit README.md again and add it to staging area * Use `git commit --amend README.md` and explain what happens * Bonus: - * Adopt the commit message using `git commit --amend` - - -~~~SECTION:handouts~~~ - -**** - -~~~ENDSECTION~~~ + * Edit the commit message using `git commit --amend` !SLIDE supplemental exercises # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Amend changes to commits @@ -52,9 +46,9 @@ problems in collaboration with others. **** * Change into `$HOME/training` -* Modify `README.md` and add docs about amend -* Add `README.md` to the staging area and commit the change -* Edit `README.md` again and add it to staging area +* Modify README.md and add more text +* Add README.md to the staging area and commit the change +* Edit README.md again and add it to staging area * Use `git commit --amend README.md` to add the change to the previous commit ## Bonus: diff --git a/day1/05_Branching/01_Intro.md b/day1/05_Branching/01_Intro.md index 0e428fc..249b114 100644 --- a/day1/05_Branching/01_Intro.md +++ b/day1/05_Branching/01_Intro.md @@ -1,29 +1,27 @@ !SLIDE subsection # ~~~SECTION:MAJOR~~~ Git Branching - -!SLIDE smbullets +!SLIDE # Working with Git branches -A git branch creates a new history line starting from the current -git commit. - -Branches are useful to develop features/fixes in their isolated +Branches are useful to develop features/fixes in an isolated environment. -* Main branch +* The default branch is usually called `main` * Note: Historically it was `master`, many vendors are now moving to `main` -* Develop a new feature in a dedicated branch -* Merge fixes into the main branch (production) -* Continue to work on the feature +* We can create dedicated branchs for development +* We can switch branches to work on this in parallel +* Once we are done developing we merge the dedicated branch into `main` + +
Feature Branch Workflow
!SLIDE smbullets # Git Branch CLI commands * `git branch` - * Create new branch without leaving the current one - * Delete branches - * List branches + * Creates a new branch + * Deletes existing branches + * Lists all available branches * `git checkout` * Switch between branches * `git merge` @@ -41,7 +39,6 @@ environment. ~~~ENDSECTION~~~ - !SLIDE smbullets # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Show the current branch @@ -51,12 +48,6 @@ environment. * Change into `$HOME/training` * Use `git branch` to highlight the current branch -~~~SECTION:handouts~~~ - -**** - -~~~ENDSECTION~~~ - !SLIDE supplemental exercises # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Show the current branch @@ -89,7 +80,6 @@ environment. $ git branch * main - !SLIDE smbullets # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Create and checkout a new branch @@ -101,13 +91,7 @@ environment. * List the branches with `git branch` * Checkout the new branch with `git checkout feature/docs` * Bonus: - * Explain `git checkout -b feature/docs2` - -~~~SECTION:handouts~~~ - -**** - -~~~ENDSECTION~~~ + * Explain `git checkout -b feature/more-docs` !SLIDE supplemental exercises # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Create and checkout a new branch @@ -128,7 +112,7 @@ environment. ## Bonus: -* Verify how `git checkout -b feature/docs2` works +* Verify how `git checkout -b feature/more-docs` works * Explain how it helps here **** @@ -171,8 +155,7 @@ when working with branches quite often. @@@ Sh $ git checkout main - $ git checkout -b feature/docs2 - + $ git checkout -b feature/more-docs !SLIDE smbullets # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Merge the branch @@ -181,7 +164,7 @@ when working with branches quite often. * Use `git merge` to merge the new branch * Steps: * Change into `$HOME/training` - * Modify the `README.md` and commit the change + * Edit the README.md and commit the change * Switch to the main branch * Use `git merge feature/docs` to merge the branch @@ -209,13 +192,6 @@ when working with branches quite often. $ git checkout main $ git merge feature/docs -~~~SECTION:handouts~~~ - -**** - -~~~ENDSECTION~~~ - - !SLIDE smbullets # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Delete the branch @@ -223,16 +199,10 @@ when working with branches quite often. * Delete the previously created branch * Steps: * Change into `$HOME/training` - * Use `git branch -d` to delete the selected branch + * Use `git branch -d` to delete the feature/docs branch * Bonus: * Try to delete the branch you are currently on -~~~SECTION:handouts~~~ - -**** - -~~~ENDSECTION~~~ - !SLIDE supplemental exercises # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Delete the branch @@ -247,7 +217,7 @@ when working with branches quite often. * Change into `$HOME/training` * Switch to the main branch -* Use `git branch -d feature/docs2` to delete the selected branch +* Use `git branch -d feature/docs` to delete the feature/docs branch ## Bonus: @@ -273,7 +243,7 @@ when working with branches quite often. ### Delete the previously created branch @@@ Sh - $ git branch -d feature/docs2 + $ git branch -d feature/docs ### Try to delete the current branch diff --git a/day1/05_Branching/02_head_smart_pointers.md b/day1/05_Branching/02_head_smart_pointers.md index 736feae..1c69714 100644 --- a/day1/05_Branching/02_head_smart_pointers.md +++ b/day1/05_Branching/02_head_smart_pointers.md @@ -1,20 +1,14 @@ !SLIDE smbullets -# HEAD and "smart pointers" - -A git commit is unique and identified by its SHA checksum. +# What is "HEAD" in Git? `HEAD` is a pointer to the latest commit in the current branch. -`HEAD^` identifies the second latest commit. - -`HEAD~9` points to the tenth latest commit. Counting starts at zero. +`HEAD` can be used in Git commands as reference. -This can be used for `git show`. More advanced techniques will be discussed later. - -~~~SECTION:handouts~~~ - -~~~ENDSECTION~~~ +* `HEAD^` identifies the second latest commit. +* `HEAD~9` points to the tenth latest commit. Counting starts at zero. +Hint: Git stores this information in the file `.git/HEAD`. !SLIDE smbullets # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Show the second commit @@ -25,12 +19,6 @@ This can be used for `git show`. More advanced techniques will be discussed late * Change into `$HOME/training` * Combine `git show` with `HEAD^` or `HEAD~1` -~~~SECTION:handouts~~~ - -**** - -~~~ENDSECTION~~~ - !SLIDE supplemental exercises # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Show the second commit @@ -68,18 +56,15 @@ or @@@ Sh $ git show HEAD~1 - - - !SLIDE smbullets -# Branches and "smart pointers" +# Branches and "HEAD" -`feature/docs` as branch name also points to the latest commit. +Branch names are also pointers to their respective latest commit. -You don't need to change branches to +This means, you don't need to change branches to * Show different branch histories -* Show specific commits where you don't know the commit id +* Show specific commits where you don't know the commit ID * Compare branches and committed code Example: @@ -87,14 +72,23 @@ Example: $ git show feature/docs commit b825ff86e4022a8fbcf52cb5a1d9a1984bd2a310 (feature/docs) + ~~~SECTION:handouts~~~ +**** + +We can view the content of the branch name pointer as such: + + cat .git/refs/heads/feature/foobar + fefe5d45980e72488e633b8ffbb25293d22389886 + ~~~ENDSECTION~~~ + !SLIDE smbullets # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Show history of different branch * Objective: - * Use `git log` from the main branch on another branch + * Use `git log` on the main branch and other branches * Steps: * Create a new branch aside from main, if not existing: `git checkout -b feature/docs` * Switch to the main branch @@ -103,19 +97,13 @@ Example: * Modify and commit changes * Diff current HEAD against `feature/docs` branch -~~~SECTION:handouts~~~ - -**** - -~~~ENDSECTION~~~ - !SLIDE supplemental exercises # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Show history of different branch ## Objective: Delete the branch **** -* Use `git log` from the main branch on another branch +* Use `git log` on the main branch and other branches ## Steps: diff --git a/day1/05_Branching/03_Reset_Commit.md b/day1/05_Branching/03_Reset_Commit.md index 09f0876..7cce577 100644 --- a/day1/05_Branching/03_Reset_Commit.md +++ b/day1/05_Branching/03_Reset_Commit.md @@ -2,33 +2,26 @@ # Reset Git Commits * `git reset` - * Remove the current commit(s) + * Resets the history up to a specific point * `--soft` adds changes to the staging area * `--hard` drops them -* Requires a new commit base specified with `HEAD` or any other pointer - * `HEAD~3` points to the 4th commit back in the history, resetting the latest 3 commits +* Requires a commit as parameter to which we want to reset to + * `HEAD^` resetting the last commit + * `HEAD~3` resetting the latest 3 commits Try it out with the trainer. - $ git reset --soft HEAD^ + $ git reset --soft HEAD^ # Commit IDs are also possible $ git reset --hard HEAD^ !SLIDE smbullets # Revert Git Commits * `git revert ` - * Revert some existing commit(s) -* Creates a new commit that will revert the existing commit(s) + * Reverts some existing commits + * Creates a new commit that will revert the existing commits Try it out with the trainer. - $ git revert HEAD^ - - -~~~SECTION:handouts~~~ - -**** - -~~~ENDSECTION~~~ - - + $ git revert HEAD^ # Commit IDs are also possible + $ git revert HEAD~2 diff --git a/day1/06_Server/01_Intro.md b/day1/06_Server/01_Intro.md index 2759c0c..92be2cf 100644 --- a/day1/06_Server/01_Intro.md +++ b/day1/06_Server/01_Intro.md @@ -1,13 +1,21 @@ !SLIDE subsection # ~~~SECTION:MAJOR~~~ Git Server -!SLIDE smbullets +!SLIDE # Introduction -* Central storage for repositories -* Collaboration between teams -* User based access control -* Trigger events (e.g. for CI) +A Git Server is a central storage for repositories + +* Facilitates collaboration between teams +* Offers user based access control +* Can trigger events (e.g. for CI) +* Can be connected with web interfaces + +There are collaboration suites with many features: + +* GitLab +* GitHub +* Bitbucket ~~~SECTION:handouts~~~ @@ -16,7 +24,6 @@ There is a variety of Git server tools, web interfaces and addons out there. -* GitLab * Gitea * Gogs @@ -27,23 +34,6 @@ NETWAYS also provides GitLab hosting services: * https://nws.netways.de/de/apps/gitlab/ -~~~ENDSECTION~~~ -!SLIDE smbullets -# Git Server Overview - -* Git server daemon -* Web interfaces -* Entire collaboration suites - * GitHub - * GitLab - * Bitbucket - - -~~~SECTION:handouts~~~ - -**** - - ~~~ENDSECTION~~~ !SLIDE smbullets noprint @@ -65,16 +55,15 @@ NETWAYS also provides GitLab hosting services:
GitHub
- !SLIDE smbullets -# Git Server Protocol +# Supported Protocols -* Read/write access via SSH - * `git@github.com:username/repo.git` -* HTTPS protocol (write access via oauth tokens) +Git can use different protocols to transfer data: HTTP, Secure Shell (SSH) and Git. + +* HTTPS * `https://my-gitlab.nws.netways.de/username/repo.git` +* SSH + * `git@github.com:username/repo.git` * Git protocol * `git://domain.com/repo.git` -* Local protocol - * `file:///opt/git/repo.git` - + * Hint: fast, but unencrypted and no authentication diff --git a/day1/06_Server/02_Gitlab_Introduction.md b/day1/06_Server/02_Gitlab_Introduction.md index 401be79..55660bc 100644 --- a/day1/06_Server/02_Gitlab_Introduction.md +++ b/day1/06_Server/02_Gitlab_Introduction.md @@ -7,24 +7,17 @@ system. * Git repositories * User and group management and fine granular permissions * Issue tracking and project management (dashboards, etc.) -* Merge, review, report +* Merge Requests, Code Review, Reporting * Continuous integration/deployment (CI/CD) NWS: https://nws.netways.de/de/apps/gitlab/ -~~~SECTION:handouts~~~ - -**** - -~~~ENDSECTION~~~ - -!SLIDE smbullets +!SLIDE # GitLab Editions * Free Edition, Free-forever features for individual users * Premium Edition, Enhance team productivity and coordination * Faster code reviews - * Advanced CI/CD * Enterprise agile planning * Release controls * Self-managed reliability @@ -34,10 +27,6 @@ NWS: https://nws.netways.de/de/apps/gitlab/ * Compliance * Portfolio management * Value stream management - * Free guest users - -https://about.gitlab.com/pricing/self-managed/feature-comparison/ -https://about.gitlab.com/install/ce-or-ee/ ~~~SECTION:handouts~~~ @@ -49,31 +38,3 @@ The source code is publicly available for both editions. You'll need a valid license for running EE in production. ~~~ENDSECTION~~~ - - -!SLIDE smbullets -# GitLab Components - -* Ruby on Rails application (unicorn, sidekiq) -* Nginx webserver -* PostgreSQL database backend -* Redis cache -* NodeJS for Javascript rendering -* Golang for background daemons - -It is recommended to use the Omnibus installation package or use -a managed cloud hosting service. - -~~~SECTION:handouts~~~ - -**** - - -Installation packages: https://about.gitlab.com/install/ - -More details on the manual installation instructions can be -found in the official documentation: https://docs.gitlab.com/ce/install/installation.html - -~~~ENDSECTION~~~ - - diff --git a/day1/06_Server/03_Gitlab_Installation.md b/day1/06_Server/03_Gitlab_Installation.md index 484d847..bda7e96 100644 --- a/day1/06_Server/03_Gitlab_Installation.md +++ b/day1/06_Server/03_Gitlab_Installation.md @@ -1,77 +1,10 @@ !SLIDE smbullets # Git Server Installation -This training focuses on a pre-installed GitLab instance. +This training focuses on working with a GitLab instances. -Each user gets access to NWS - https://nws.netways.de -and a GitLab CE app. +Manual installation instructions are out of scope. It is recommended to use: -GitLab supports working with - -* SSH -* HTTPS - -Manual installation instructions are provided in the -handout. - -~~~SECTION:handouts~~~ - -**** - -~~~ENDSECTION~~~ - - -!SLIDE smbullets -# Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Create GitLab app in NWS - -**Note**: Skip this lab if already done. - -* Objective: - * Create a new GitLab app in NWS -* Steps: - * Navigate to https://nws.netways.de and register a trial account if not existing - * Choose Apps > GitLab CE > Basic - * Deploy the app - * Choose Access and Live View and set a secure password for the `root` user - * Login - -~~~SECTION:handouts~~~ - -**** - - -~~~ENDSECTION~~~ - -!SLIDE supplemental exercises -# Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Create GitLab Project - -## Objective: Create a new GitLab app in NWS -**** - -* Create a new GitLab app in NWS - -## Steps: - -**** - -* Navigate to https://nws.netways.de and register a trial account if not existing -* Choose Apps > GitLab CE > Basic -* Deploy the app -* Choose Access and Live View and set a secure password for the `root` user -* Login - - -!SLIDE supplemental solutions -# Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Proposed Solution -**** - -## Create a new GitLab app in NWS - -**** - -Open https://nws.netways.de in your browser and register your -personal account. Login and navigate to Apps > GitLab CE > Basic -and deploy the app. - -Use Access and Live View and set a secure root password. -Then login into GitLab. +* The "Omnibus Installation" package +* The GitLab Container Images +* A managed cloud hosting service diff --git a/day1/06_Server/04_Connect_Local_Remote.md b/day1/06_Server/04_Connect_Local_Remote.md index f1bac38..bc64bca 100644 --- a/day1/06_Server/04_Connect_Local_Remote.md +++ b/day1/06_Server/04_Connect_Local_Remote.md @@ -1,56 +1,3 @@ -!SLIDE smbullets -# Connect Local Repository to Remote Server - -* Local standalone repository -* Connect to remote server -* Clone, Pull, Fetch, Push via SSH/HTTPS - -You can also start fresh without any local repository -and clone that from remote. - -For training purposes we've started to work offline in `$HOME/training`. -Now we want to publish the local commits to a newly created Git repository -in GitLab. - -~~~SECTION:handouts~~~ - -**** - - - -~~~ENDSECTION~~~ - -!SLIDE smbullets -# Requirements - -* SSH or HTTPS auth - * NWS apps come pre-defined with HTTPS clone/fetch only -* New GitLab repository for this user -* Configure local repository for the remote server - -~~~SECTION:handouts~~~ - -**** - -**SSH Keys** - -Generate a new SSH key pair on your client. - -``` -ssh-keygen -t ed25519 -``` - -Copy the public key into your GitLab settings. - -``` -cat $HOME/.ssh/id_ed25519.pub -``` - -User > Settings > SSH Keys - - -~~~ENDSECTION~~~ - !SLIDE smbullets # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Create GitLab Project @@ -62,17 +9,11 @@ User > Settings > SSH Keys * Choose `New Project` * Add the name `training` * Leave it as `Private` + * Untick `Initialize repository with a README` for an empty project * Create the project * Note: * Learn about the project view and the HTTPS clone URL -~~~SECTION:handouts~~~ - -**** - - -~~~ENDSECTION~~~ - !SLIDE supplemental exercises # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Create GitLab Project @@ -89,6 +30,7 @@ User > Settings > SSH Keys * Choose `New Project` * Add the name `training` * Leave it as `Private` +* Untick `Initialize repository with a README` for an empty project * Create the project ## Note: @@ -110,7 +52,7 @@ User > Settings > SSH Keys GitLab 10.x provides `New Project` underneath the `+` icon in the top menu bar, next to the search form. -Fill in the `Project name` form with `training` and leave the +Fill in the `Project name` form with `training`, untick `Initialize repository with a README` for an empty project and leave the other options as default. ### Project View @@ -125,38 +67,169 @@ GitLab offers you to add new files, e.g. a README.md file or LICENSE details directly in the browser. In the background, it is still comitting the changes to the Git repository. +!SLIDE +# GitLab Issues and Boards + +Issues can be used for planning and tracking work (feature requests, bugfixes, questions). + +Issues can be annotated with labels. + +Milestones allow you to organize issues into a cohesive group. + +The issue board is a software project management tool used to plan, organize, and visualize a workflow for a feature or product release. + +* Kanban or Scrum board +* Filter by labels +* Drag & drop issues !SLIDE smbullets -# Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Add the repository as remote origin +# Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Create Milestone and Issues -* Objective: - * Add the GitLab project as remote origin -* Steps - * Open the project in GitLab and extract the `HTTPS` clone URL - * Navigate into your local repository in `$HOME/training` - * Use `git remote add origin ` - * Push local branches with `git push -u origin --all` +* Objective + * Create Milestone `v1.0` + * Create Issue `Update documentation` + +* Steps: + * Navigate into `Issues > Milestones` + * Select `New Milestone` and use `v1.0` as title + * Navigate to `Issues` and select `New issue` + * Use `Update documentation` as title, add a description + * Assign the `v1.0` milestone + +!SLIDE supplemental exercises +# Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Create Milestone and Issues + +## Objective: Create Milestone and First Issue +**** + +* Create Milestone and First Issue + +## Steps: + +**** + +* Navigate into `Issues > Milestones` +* Select `New Milestone` and use `v1.0` as title +* Navigate to `Issues` and select `New issue` +* Use `Update documentation` as title, add a description +* Assign the `v1.0` milestone + +!SLIDE smbullets +# Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Add Project Members + +* Objective + * Add the trainers as Project members + +* Steps: + * Navigate into `Project information > Members` + * Use `Invite members` and search for the trainers + * Select the `Developer` role and add the trainers * Bonus - * Set default push method to `simple` + * Add a colleague or participant as `Guest` + +!SLIDE supplemental exercises +# Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Add Project Members + +## Objective: Add the trainers as Project members +**** + +* Add the trainers as Project members + +## Steps: + +**** + +* Navigate into `Project information > Members` +* Use `Invite members` and search for the trainers +* Select the `Developer` role and add the trainers + +!SLIDE +# GitLab Project Snippets + +With GitLab snippets, you can store and share bits of code and text with other users. + +* Snippet visibility can differ from the project's visibility +* Are version controlled and have syntax highlighting +* URL is stable and can be shared + +Example use cases: + +* Guides for less code-savvy people +* Documentation for hard to automate but regular tasks + +Can be cloned because they are stored with Git. + +Try it out with the trainer. + +~~~ENDSECTION~~~ + +!SLIDE +# GitLab Project Wiki + +Every wiki is a separate Git repository, within the project. + +* Support Markdown, Rdoc, AsciiDoc, and Org for content +* Hierarchical links possible +* Mermaid diagrams and charts can be included + +Example use cases: + +* Additional documentation for the project + +Can be cloned because they are stored with Git. + +Try it out with the trainer. + +~~~ENDSECTION~~~ + +!SLIDE smbullets +# Connect Local Repository to Remote Server + +We can either start a local repository and connect it to a remote server, or clone an existing repository. + +* Endpoints for the remote servers are called `remote` in Git. +* Communication is done via SSH/HTTPS (SSH is recommended) +* We need a remove for: `clone`, `push`, `pull` + +For training purposes we've started to work offline in `$HOME/training`. + +Now we want to publish the local commits to a newly created Git repository +in GitLab. ~~~SECTION:handouts~~~ **** -There are various `push` methods: +**SSH Keys** -* `simple` - pushes the current branch with the same name on the remote -* `current` - push the current branch to update a branch with the same name on the receiving end -* `nothing` - do not push anything (error out) unless a refspec is given +Generate a new SSH key pair on your client. + +``` +ssh-keygen -t ed25519 +``` -References: +Copy the public key into your GitLab settings. -https://git-scm.com/docs/git-config/#Documentation/git-config.txt-pushdefault +``` +cat $HOME/.ssh/id_ed25519.pub +``` +User > Settings > SSH Keys ~~~ENDSECTION~~~ +!SLIDE smbullets +# Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Add the repository as remote origin + +* Objective: + * Add the GitLab project as remote origin +* Steps + * Open the project in GitLab and extract the `HTTPS` clone URL + * Navigate into your local repository in `$HOME/training` + * Use `git remote add origin ` + * Push the main branch with `git push origin main` + !SLIDE supplemental exercises # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Add the repository as remote origin @@ -171,14 +244,8 @@ https://git-scm.com/docs/git-config/#Documentation/git-config.txt-pushdefault * Open the project in GitLab and extract the `HTTPS` clone URL * Navigate into your local repository - * Use `git remote add origin ` -* Push local branches with `git push -u origin --all` - -## Bonus: - -**** - -* Configure the default push method to `simple` +* Use `git remote add origin ` +* Push the main branch with `git push origin main` !SLIDE supplemental solutions # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Proposed Solution @@ -206,7 +273,7 @@ Use `--set-upstream` as proposed by the cli output. Short form is `-u`. @@@ Sh $ cd $HOME/training.git $ git remote add origin https://[...].nws.netways.de/root/training.git - $ git push -u origin --all + $ git push origin main ### Set default push method @@ -238,32 +305,24 @@ use `--all` instead. Keep in mind that syncing all your local branches might create unwanted remote branches. Those can be there just for testing things, or are not meant for the public domain. - !SLIDE smbullets # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Add a credential cache * Objective: - * Add the credentail cache to the configuration + * Add the credential cache to the configuration * Steps * Go to your terminal * Use `git config credential.helper 'cache --timeout=99999'` This is only for the training. In reality use SSH authentication. -~~~SECTION:handouts~~~ - -**** - - -~~~ENDSECTION~~~ - !SLIDE supplemental exercises # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Add a credential cache -## Objective: Add the credentail cache to the configuration +## Objective: Add the credential cache to the configuration **** -* Add the credentail cache to the configuration +* Add the credential cache to the configuration ## Steps: @@ -305,14 +364,6 @@ This is only for the training. In reality use SSH authentication. * Bonus: * Use `Repository > Graph` in GitLab -~~~SECTION:handouts~~~ - -**** - - - -~~~ENDSECTION~~~ - !SLIDE supplemental exercises # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Explore Project History @@ -346,9 +397,8 @@ This is only for the training. In reality use SSH authentication. Choose `History` and look at the Git commits, their author, subject and timestamp. -Compare it with the local `git log` or `tig` entries. +Compare it with the local `git log` or `tig` entries. ### GitLab Graphs Navigate into `Repository > Graph` to get an alternative history view. - diff --git a/day1/07_Collaboration/01_Intro.md b/day1/07_Collaboration/01_Intro.md index 0eb0dcf..a53d2cc 100644 --- a/day1/07_Collaboration/01_Intro.md +++ b/day1/07_Collaboration/01_Intro.md @@ -4,16 +4,9 @@ !SLIDE smbullets # Collaboration -* Work locally -* Push to remote repository -* Share your work with others -* Review, discuss, collaborate -* Change, adopt, release - -~~~SECTION:handouts~~~ - -**** - - -~~~ENDSECTION~~~ +A common workflow when working with others is: +* Each person works locally +* Finished work is pushed to remote repository +* We review and discuss the changes +* We merge the changes into our main branch diff --git a/day1/07_Collaboration/02_Collaboration.md b/day1/07_Collaboration/02_Collaboration.md index 11e5fdb..d8dfd43 100644 --- a/day1/07_Collaboration/02_Collaboration.md +++ b/day1/07_Collaboration/02_Collaboration.md @@ -2,19 +2,18 @@ # Collaboration: Put History * `git push` - * Update remote references and push local history to remote repository - * This pushes source code changes and commits + * Pushes the local history to the remote repository * Halts if the remote history diverged from your local history * `git remote` - * Configure/list remote repository URLs (default `origin`) + * Adds remote repository URLs (default `origin`) + * Lists and removes remote repository URLs * `git branch -r` - * List remote branches, prefixed with the remote name, e.g. `origin/main` + * Lists remote branches, prefixed with the remote name, e.g. `origin/main` ~~~SECTION:handouts~~~ **** - `git push` updates remote references and pushes your local commit history to the remote repository. `git remote` allows you to configure and list the remote repository. By default this is called `origin`. @@ -28,18 +27,12 @@ * Learn more about git push * Steps: * Change into `$HOME/training` - * Edit `README.md` and add a note on `git push` + * Edit `README.md` and notes about `git push` * Add and commit the changes * Push the changes * Bonus: * List all remote branches with `git branch -r` -~~~SECTION:handouts~~~ - -**** - -~~~ENDSECTION~~~ - !SLIDE supplemental exercises # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Learn more about git push @@ -51,7 +44,7 @@ ## Steps: * Change into `$HOME/training` -* Edit `README.md` and add a note on `git push` +* Edit `README.md` and add notes about `git push` * Add and commit the changes * Push the changes @@ -90,41 +83,180 @@ @@@ Sh $ git branch -r -!SLIDE smbullets +!SLIDE # Collaboration: Branch Tracking -* Local branches track remote branches -* Use same names for local and remote branches - * Enables "simple" push with `git push` in the current checked out branch +A *tracking branch* is a local branch that is connected to a remote branch. + +* We can now push without the need to be specific(`git push origin main`) +* Git can now inform you about "unpushed" and "unpulled" commits (`git status`) * `git branch -a` lists all branches -* Use `git branch -vv` to list tracking +* `git branch -vv` lists tracking branches Example: @@@ Sh git branch -vv - feature/config 7b36d4a [origin/feature/] Add flag to extend config - fix/replication 324882e [origin/fix/replication: gone] Fix bug #231 - *master f2cce0c [origin/master] Rename test directory - wip-foobar d92a5ad Why wont it work?! + *master f2cce0c [origin/master] Rename test directory + wip-foobar d92a5ad Why wont it work?! + +Hint: There are various `push` methods that can be configured. ~~~SECTION:handouts~~~ **** +There are various `push` methods: + +* `simple` - pushes the current branch with the same name on the remote +* `current` - push the current branch to update a branch with the same name on the receiving end +* `nothing` - do not push anything (error out) unless a refspec is given + +References: + +https://git-scm.com/docs/git-config/#Documentation/git-config.txt-pushdefault ~~~ENDSECTION~~~ +!SLIDE smbullets +# Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Configure a tracking branch + +* Objective: + * Set the origin/main as tracking branch for main +* Steps: + * Change into `$HOME/training` + * Push with `git push` explain the error + * Push with `git push --set-upstream origin main` + * Push again with `git push` +* Bonus: + * Verify the tracking branches with `git branch -vv` + +!SLIDE supplemental exercises +# Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Configure a tracking branch + +## Objective: Set the origin/main as tracking branch for main +**** + +* Set the origin/main as tracking branch for main + +## Steps: + +* Change into `$HOME/training` +* Push with `git push` explain the error +* Push with `git push --set-upstream origin main` +* Push again with `git push` + +## Bonus: + +* Verify the tracking branches with `git branch -vv` + +!SLIDE supplemental solutions +# Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Proposed Solution +**** + +## Set the origin/main as tracking branch for main + +**** + +### Make changes + + @@@ Sh + $ cd $HOME/training + $ git checkout main + + $ git push + $ # fatal: The current branch foobar has no upstream branch. + $ git push --set-upstream origin main + $ git push + +### List tracking branches + + @@@ Sh + $ git branch -vv + + +!SLIDE smbullets +# Deleting Remote Branches + +You have learned that you can create remote (feature) branches. But what if +you want to delete such branches? + +`git push origin ` is short for `git push origin :`. + +Pushing `NULL` into a remote branch will delete it. + +`git push origin :` + +Hint: You can delete branches in GitLab/GitHub too. + +!SLIDE smbullets +# Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Delete remote branch + +* Objective: + * Delete remote branch +* Steps: + * Change into `$HOME/training` + * Create or identify a remote branch `feature/docs-wrong-name` + * Delete the remote branch + +!SLIDE supplemental exercises +# Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Delete remote branch + +## Objective: Delete remote branch +**** + +* Delete remote branch + +## Steps: + +* Change into `$HOME/training` +* Create or identify a remote branch `feature/docs-wrong-name` +* Delete the remote branch + +!SLIDE supplemental solutions +# Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Proposed Solution +**** + +## Delete remote branch + +**** + +### Create and push remote branch + +If you do not have any. + + @@@ Sh + $ cd $HOME/training + $ git checkout main + $ git checkout -b feature/docs-wrong-name + $ git push -u origin feature/docs-wrong-name + +### Identify remote branch to delete + + @@@ Sh + $ git branch -r + feature/docs-wrong-name + +### Delete remote branch + + @@@ Sh + $ git push origin :feature/docs-wrong-name + +Now verify it is gone (Hint: `-r` lists remote branches). + + @@@ Sh + $ git fetch + $ git branch -r !SLIDE smbullets # Collaboration: Get History * `git fetch` - * Update the remote branch reference pointers to the latest commit and cache it locally - * Does not pull in any remote commit history + * Downloads data from a remote repository + * The changes from the remote repository are not integrated into local branches * `git pull` - * Fetch and update the local history from remote repository (implicit fetch) - * This pulls in source code changes and commits + * Downloads data from a remote repository and integrates them into local branches + * git pull runs `git fetch` and either `git rebase` or `git merge` behind the scences ~~~SECTION:handouts~~~ @@ -134,11 +266,8 @@ Example: `git pull` invokes a fetch and updates the local history with commits from the remote repository. - ~~~ENDSECTION~~~ - - !SLIDE smbullets # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Learn more about git fetch and git pull @@ -151,12 +280,6 @@ Example: * Run `git pull` * Explain the difference -~~~SECTION:handouts~~~ - -**** - -~~~ENDSECTION~~~ - !SLIDE supplemental exercises # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Learn more about git fetch and git pull @@ -219,4 +342,3 @@ updated with the remote history. @@@ Sh $ git log $ git diff main origin/main - diff --git a/day1/07_Collaboration/04_Advanced.md b/day1/07_Collaboration/04_Advanced.md index b14b11b..cf55ce4 100644 --- a/day1/07_Collaboration/04_Advanced.md +++ b/day1/07_Collaboration/04_Advanced.md @@ -2,18 +2,26 @@ # Advanced Git Commands: Stash * `git stash` - * Put current changes on a temporary stack - * Useful when changing branches (diff would not apply) - * Use with care, pop changes immediately after changing back - * Only local, not stored in the central repository + * Moves the current working directory to a temporary stack + * The stash is only local, not stored in the central repository + * Useful when changing branches or pulling + * Use with care, apply and drop changes immediately after changing back Example: @@@ Sh $ git stash Saved working directory and index state WIP on main: 4b4f6c2 + + $ git stash apply + On branch main + Your branch is up to date with 'origin/main'. + + Changes to be committed: + (use "git restore --staged ..." to unstage) + new file: - $ git stash pop + $ git stash drop Dropped refs/stash@{0} (43d879b99aca12b6175c5362339b177af22589a9) ~~~SECTION:handouts~~~ @@ -23,12 +31,14 @@ Example: `git stash` allows you put your current changes on a temporary stack (`stash`). This comes in handy when you want to change branches with a different history where your uncommitted changes will not apply. -Use `git stash pop` to fetch the changes again. You can stash multiple uncommitted +Use `git stash apply` to copy them from the stash to your working directory again. +Use `git stash drop` to remove your stashed changes. + +You can stash multiple uncommitted stages, `git stash list` will list them. ~~~ENDSECTION~~~ - !SLIDE smbullets # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Learn more about git stash @@ -41,13 +51,8 @@ stages, `git stash list` will list them. * Stash your current changes to the working directory * Run git status again * Examine the stash with `git stash list` and `git stash show -p` - * Fetch the previously stashed changes with `git stash pop` - -~~~SECTION:handouts~~~ - -**** - -~~~ENDSECTION~~~ + * Fetch the previously stashed changes with `git stash apply` + * Drop the stashed changes with `git stash drop` !SLIDE supplemental exercises # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Learn more about git stash @@ -65,12 +70,14 @@ stages, `git stash list` will list them. * Stash your current changes to the working directory * Run git status again * Examine the stash with `git stash list` and `git stash show -p` -* Fetch the previously stashed changes with `git stash pop` + * Fetch the previously stashed changes with `git stash apply` + * Drop the stashed changes with `git stash drop` !SLIDE supplemental solutions # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Proposed Solution **** + ## Learn more about git stash **** @@ -128,29 +135,35 @@ stages, `git stash list` will list them. ### Fetch previously stashed changes @@@ Sh - $ git stash pop + $ git stash apply + On branch main + Your branch is up to date with 'origin/main'. + + Changes to be committed: + (use "git restore --staged ..." to unstage) + new file: README.md + +### Drop the stashed changes + + @@@ Sh + $ git stash drop + Dropped refs/stash@{0} (a9f28340e6d536a9179307bd26169368e450161f) - !SLIDE smbullets # Advanced Git Commands: Cherry-Pick * `git cherry-pick` - * Collect specific commit into your working tree - * Applies the contained patch - * When the base commit differs, checksum changes = new commit id - * Use `git cherry-pick -x ` to add source comment - -~~~SECTION:handouts~~~ - -**** + * Integrates a specific commit into your working tree + * Hint: When the base commit differs, the checksum changes, thus new commit ID + * `-x` can be used to keep a reference to the original commit -`git cherry-pick` collects a specific commit into your working tree. +Example: + $ git cherry-pick -x ef5d1c2 -~~~ENDSECTION~~~ !SLIDE smbullets # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Learn more about git cherry-pick @@ -165,13 +178,6 @@ stages, `git stash list` will list them. * Use `git cherry-pick -x ` * Verify the commit with `git show` -~~~SECTION:handouts~~~ - -**** - -~~~ENDSECTION~~~ - - !SLIDE supplemental exercises # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Learn more about git cherry-pick @@ -238,7 +244,7 @@ stages, `git stash list` will list them. @@@ Sh $ git show commit 2f3a0096017051d9ab86774282203dc6c9827ee4 (HEAD -> main) - Author: Michael Friedrich + Author: Guy Incognito Date: Thu Jan 24 14:52:19 2019 +0100 Update docs for cherry-pick diff --git a/day1/07_Collaboration/03_Tags.md b/day1/07_Collaboration/05_Tags.md similarity index 66% rename from day1/07_Collaboration/03_Tags.md rename to day1/07_Collaboration/05_Tags.md index b6a55a5..4d0c1bf 100644 --- a/day1/07_Collaboration/03_Tags.md +++ b/day1/07_Collaboration/05_Tags.md @@ -1,13 +1,14 @@ !SLIDE smbullets # Git Tags -* Tag specific points in history -* Add, list, delete -* Push tags to remote repository -* Checkout branches based on tags +Tags are specific points in history, they point to a commit. Useful for: + * Release software versions based on tags (e.g. v2.9.0) +* Checkout versions based on tags * Tags can/should follow milestone versions in ticket systems +They can be *lightweight* or be *annotated*. + ~~~SECTION:handouts~~~ **** @@ -20,51 +21,43 @@ Example for checking out a tag into a new branch: ~~~ENDSECTION~~~ - !SLIDE smbullets -# Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Add Git Tag +# Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Add a Git tag * Objective: - * Add git tag + * Add a Git tag * Steps: - * Use `git tag` and add the `v0.1` tag + * Use `git tag` and add the `v0.5` tag * Verify the added tag with `git tag -l` * Push tags to remote origin with `git push --tags` * Open GitLab and navigate into `Repository > Tags` * Bonus: - * Add a tag description with `git tag -m "Release v0.1" v0.1` - -~~~SECTION:handouts~~~ - -**** - -~~~ENDSECTION~~~ + * Add a tag description with `git tag -m "End Of Day One Release" v0.5` !SLIDE supplemental exercises -# Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Add Git Tag +# Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Add a Git tag -## Objective: Add git tag +## Objective: Add a Git tag **** * Add git tag ## Steps: -* Use `git tag` and add the `v0.1` tag +* Use `git tag` and add the `v0.5` tag * Verify the added tag with `git tag -l` * Push tags to remote origin with `git push --tags` * Open GitLab and navigate into `Repository > Tags` ## Bonus: -* Add a tag description with `git tag -m "Release v0.1" v0.1` - +* Add a tag description with `git tag -m "End Of Day One Release" v0.5` !SLIDE supplemental solutions # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Proposed Solution **** -## Add git tag +## Add a Git tag **** diff --git a/day2/01_Workflows/05_Gitlab_Workflow.md b/day2/01_Workflows/05_Gitlab_Workflow.md index 694fdbb..38aeb2c 100644 --- a/day2/01_Workflows/05_Gitlab_Workflow.md +++ b/day2/01_Workflows/05_Gitlab_Workflow.md @@ -22,46 +22,8 @@ **** - -~~~ENDSECTION~~~ - -!SLIDE smbullets -# Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Create Milestone and first Issue - -* Objective - * Create Milestone `v0.1` - * Create Issue `Update documentation` - -* Steps: - * Navigate into `Issues > Milestones` - * Select `New Milestone` and use `v0.1` as title - * Navigate to `Issues` and select `New issue` - * Use `Update documentation` as title, add a description - * Assign the `v0.1` milestone - -~~~SECTION:handouts~~~ - -**** - ~~~ENDSECTION~~~ -!SLIDE supplemental exercises -# Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Create Milestone and First Issue - -## Objective: Create Milestone and First Issue -**** - -* Create Milestone and First Issue - -## Steps: - -**** - -* Navigate into `Issues > Milestones` -* Select `New Milestone` and use `v0.1` as title -* Navigate to `Issues` and select `New issue` -* Use `Update documentation` as title, add a description -* Assign the `v0.1` milestone !SLIDE supplemental solutions # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Proposed Solution @@ -73,9 +35,6 @@ Follow the instructions and ask the trainer for help. - - - !SLIDE smbullets # Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Create Merge Request diff --git a/day2/01_Workflows/10_Delete_Remote_Branches.md b/day2/01_Workflows/10_Delete_Remote_Branches.md deleted file mode 100644 index c172f94..0000000 --- a/day2/01_Workflows/10_Delete_Remote_Branches.md +++ /dev/null @@ -1,80 +0,0 @@ -!SLIDE smbullets -# More Hints: Delete Remote Branches - -You have learned that you can create remote (feature) branches. But what if -you want to delete such branches? - -`git push origin ` is short for `git push origin :`. - -Pushing `NULL` into a remote branch will delete it. - -`git push origin :` - -Hint: You can delete branches in GitLab/GitHub too. - -!SLIDE smbullets -# Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Delete remote branch - -* Objective: - * Delete remote branch -* Steps: - * Change into `$HOME/training` - * Create or identify a remote branch `feature/docs-wrong-name` - * Delete the remote branch - -~~~SECTION:handouts~~~ - -**** - -~~~ENDSECTION~~~ - -!SLIDE supplemental exercises -# Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Delete remote branch - -## Objective: Delete remote branch -**** - -* Delete remote branch - -## Steps: - -* Change into `$HOME/training` -* Create or identify a remote branch `feature/docs-wrong-name` -* Delete the remote branch - -!SLIDE supplemental solutions -# Lab ~~~SECTION:MAJOR~~~.~~~SECTION:MINOR~~~: Proposed Solution -**** - -## Delete remote branch - -**** - -### Create and push remote branch - -If you do not have any. - - @@@ Sh - $ cd $HOME/training - $ git checkout main - $ git checkout -b feature/docs-wrong-name - $ git push -u origin feature/docs-wrong-name - -### Identify remote branch to delete - - @@@ Sh - $ git branch -r - feature/docs-wrong-name - -### Delete remote branch - - @@@ Sh - $ git push origin :feature/docs-wrong-name - -Now verify it is gone (Hint: `-r` lists remote branches). - - @@@ Sh - $ git fetch - $ git branch -r - - diff --git a/day2/05_Outlook/01_GitLab_Features.md b/day2/05_Outlook/01_GitLab_Features.md index dd0c697..a0061fb 100644 --- a/day2/05_Outlook/01_GitLab_Features.md +++ b/day2/05_Outlook/01_GitLab_Features.md @@ -1,48 +1,6 @@ !SLIDE subsection # ~~~SECTION:MAJOR~~~ Further GitLab Features -!SLIDE smbullets -# Project Issue Boards - -The issue board is a software project management tool used to plan, organize, and visualize a workflow for a feature or product release. - -* Kanban or Scrum board -* Filter by labels -* Drag & drop issues - -~~~ENDSECTION~~~ - -!SLIDE smbullets -# Project Snippets - -With GitLab snippets, you can store and share bits of code and text with other users. - -* Snippet visibility can differ from the project's visibility -* Are version controlled and have syntax highlighting -* URL is stable and can be shared - -Example use cases: - -* Guides for less code-savvy people -* Documentation for hard to automate but regular tasks - -~~~ENDSECTION~~~ - -!SLIDE smbullets -# Project Wiki - -Every wiki is a separate Git repository, within the project. - -* Support Markdown, Rdoc, AsciiDoc, and Org for content -* Hierarchical links possible -* Mermaid diagrams and charts can be included - -Example use cases: - -* Additional documentation for the project - -~~~ENDSECTION~~~ - !SLIDE smbullets # Container and Package Registry