You are on page 1of 60

Getting Started

What & Why?


What are Git
& GitHub?
What is Version Management/Control?

Multiple Files Single File Version Management

First Draft
First Draft Second Draft

Third Draft
Third Draft

Another draft Final Final


Final
Control & tracking
of code changes*
over time
About Git & GitHub

Version Control System Largest Development Platform

Cloud Hosting &


Manage Code History
Collaboration Provider

Track Changes Git Repository Hosting


Course Content

Local vs
Windows Commits & Branches
Remote Repositories
Command Prompt The Basics
The Basics

Merging, Pull Requests,


Mac Terminal
Rebasing & More Organizations & More
(Z shell)
Deep Dive Deep Dive

Optional Git GitHub Practice Project


How To Get The Most Out Of The Course

Watch the Videos


(choose your pace)

Code Along & Practice


(also without us telling you)

Debug Errors & Explore Solutions


(also check attachments)

Help Each Other & Learn Together


(Discord, Q&A Board)
Optional: Command Line Basics

Text Based Computer Interaction


Module Content

Text Based Computer Interaction – What & Why?

Mac User: Z-Shell Basics

Windows User: Command Prompt Basics


Text Based Computer Interaction – What & Why

Graphical User Interface (GUI) Command Prompt


Start Servers

Download + Install Tools

Run Code

Execute Files
User Friendly Time Saving

Working with Git


Easy to Explore More Possibilities
Mac Terminology

Terminal Shell

Text Input Interface


Text Input Environment (“Hardware“)
(“Software“)

Bash zsh (Z-Shell)


Windows Terminology

Command Prompt (cmd) PowerShell Git Bash

Initial Windows Shell New Shell (Windows 7


Release) Bash Emulation for Windows
Command Line Tools

Command Prompt Terminal


(cmd) (z-Shell)
Mac: Terminal (z-Shell) – Useful Commands

pwd cd /Users rm
(print working directory) (users directory) (delete file)

ls cd or cd ~ rmdir
(list items) (home directory) (delete empty folder)

cd (..) touch cp
(change directory) (create/ ”touch” file) (copy file/folder)

cd / mkdir mv
(root directory) (create directory) (move file/folder)
Windows: Command Prompt – Useful Commands

cd echo text > name(.type) copy file


(print current path) (create file) (copy file)

dir mkdir foldername move file folder


(list items) (create directory) (move file or folder)

cls del file


(clear command prompt) (delete file)

cd (..) rmdir folder


(change directory) (delete folder)
Version Management with Git

The Basics
Module Content

Theory – How Git Works

Installation & Development Environment

Repositories, Branches & Commits


How Does Git Work – Simplified!
“master“ branch

Working Directory

Commit
“Snapshot 1“ index.html styles.css images

Web Shop

Commit
“Snapshot 2“ styles.css

index.html styles.css images

Commit
“Snapshot 3“ script.js
Git under the Hood

Working Directory .git (hidden) Repository

Staging Area Commits


(Index File) (Objects Folder)
index.html styles.css images

add commit
styles.css styles.css styles.css

Git = Tracking changes - NOT storing files again and again!


Branches & Commits

Working Directory/Tree Working Directory/Tree

Master Branch Landing-Page Branch

Commit 1 Commit 2 Commit 3 Commit 1 Commit 2 Commit 3 Commit 4


What is the “HEAD“?
head

master c.1 c.2 c.3

head

other c.1 c.2 c.3 c.4


The “detached HEAD“

master c.1 c.2 c.3

Detached HEAD

other c.1 c.2 c.3 c.4


“HEAD“ vs “detached HEAD“

HEAD Indirectly points to commit

git checkout branchname

Points to branch which points to commit

Detached HEAD Directly points to commit

git checkout commitid

Points to commit with specified ID

Commit is not related to specific branch


Deleting Data

Working Directory Files


(already part of previous commit)

Unstaged Changes

Staged Changes

Latest Commit(s)

Branches
Basic Commands Summary: General

git --version Check installed Git version

git init Create empty Git repository

Check working directory &


git status
staging area status

Display all commits of current


git log
branch

git ls-files List tracked files


Basic Commands Summary: Commit Creation & Access

git add filename Add single file or all WD files to


git add . staging area

git commit –m
Create new commit
“message“

Checkout commit (detached


git checkout commitid
head!)
Basic Commands Summary: Branch Creation & Access

Git 2.23+

git branch branchname git switch branchname Create new branch

git checkout
Go to branch
branchname

git checkout –b git switch –c


Create and access new branch
branchname branchname

Bring other branch‘s changes to


git merge otherbranch
current branch
Basic Commands Summary: Deleting Data
git rm filename Run command after file was
WD File*
git add filename deleted from working directory

git checkout (--) .


Revert changes in tracked files
Unstaged 2.23 git restore filename or .
Changes
git clean -df Delete untracked files
Delete/Undo

git reset filename &


Staged Remove file(s) from
git checkout –– filename
Changes staging area
2.23 git restore ––staged filename or .

git reset HEAD~1


Latest
git reset ––soft HEAD~1 Undo latest ( ~1) commit
Commit(s)
git reset ––hard HEAD~1

Branches git branch –D branchname Delete branch

* Already part of previous commit


Diving Deeper Into Git

Beyond The Basics


Module Content

Diving Deeper into Commits

Managing & Combining Different Branches

Resolving Conflicts
Combining Master & Feature Branches

Master = Main project branch

Feature = Separate branch “based“ on


master branch

? ?

Goal:
Combining master & feature branch
Merge Types

Fast-Forward

Non Fast-Forward

Recursive Octopus

Ours Subtree
Master & Feature – Merge (“fast-forward“)

No additional commit in
master m.1 m.2 ?
master
(after feature branch was
created)

Merge moves HEAD


forward but does not
create new commit!
feature m.1 m.2 f.1 f.2
Master & Feature – Merge (“recursive“)

Additional commits in
master m.1 m.2 m.3 ?
both master & feature
branch after feature
branch was created

Additional (merge) commit


is created in master
branch
feature m.1 m.2 f.1 f.2
Master & Feature – Rebase

master m.1 m.2 m.3 f.1 f.2

feature m.1 m.2 f.1 f.2


Rebase – What happened?

“m.3“ becomes new base commit for


commits created in feature branch

rebase master to feature branch


master m.1 m.2 m.3 f.1 f.2

merge rebased feature into master

feature m.1 m.2 m.3


f.1 f.1
f.2 f.2

“rebase“does not move commits, it


creates new commits
---
Never rebase commits outside your
repository!
Rebase – When to Apply?

New commits in master branch while working in feature branch

Feature relies on additional commits in master Feature is finished – Implementation into


branch master without merge commit

Rebase master into feature +


Rebase master into feature branch
(fast-forward) merge feature into master

Remember: Rebasing re-writes code history!


Merge vs Rebase vs Cherry-Pick

Merge
Rebase Cherry-Pick
(non fast-forward)

Add specific commit to branch


Create merge commit Change single commit‘s parent
(HEAD)

Copies commit with


New commit New commit ID(s)
new ID
Deep Dive Summary

git stash Temporary storage for unstaged and uncommitted changes

git reflog A log of all project changes made including deleted commits

Combining commits from different branches by creating a new merge commit


git merge
(recursive) or by moving the HEAD (fast-forward)

git rebase Change the base (i.e. the parent commit) of commits in another branch

Copy commit including the changes made only in this commit as HEAD to other
git cherry-pick
branch
Understanding GitHub

Leaving the Local Repository


Module Content

What is GitHub &


How Git & GitHub are Connected

Remote Branches, Remote Tracking Branches & Local Tracking


Branches

Understanding Upstreams & Git Clone


About Git & GitHub

Version Control System Largest Development Platform

Cloud Hosting &


Manage Code History
Collaboration Provider

Track Changes Git Repository Hosting


Connecting Git & Github – Local to Empty Remote Repo

git push

Local Repository git remote add origin URL Remote Repository

git pull

“Name of the remote machine“ or


alias/shorthand of the URL of the remote repository
More Branches?

git push origin master git pull origin master

Local Branch master master

git merge

Remote Tracking Branch remotes/origin/master remotes/origin/master

git fetch

Remote Branch
master master
(“origin“ repository)

Remote repository‘s name (“origin“) and branch name must always be added
Branch Types - Overview

Branch on your machine only (as


Local Branch
seen in the course)

Branch in remote location


Remote Branch
(e.g. in GitHub)

Tracking Branch

Local copy of remote branch (not


Remote Tracking Branch git fetch
to be edited)

Local reference to remote tracking git push


Local Tracking Branch
branch (to be edited) git pull
Local & Remote Tracking Branches

Remote Branch git remote Show remote servers

git fetch

git branch -a List all branches


Remote Tracking Branch
git branch –r Show remote tracking branches
Local cache of remote branch‘s content
git remote show origin Show detailed configuration

git merge git push

List local tracking branches and their


Local Tracking Branch git branch –vv
remotes

Remote repository‘s name (“origin“) and branch name can


git branch –-track
Create local tracking branch
be omitted branchname origin/branchname
Connecting Git & Github – Remote to Empty Local Repo

git push

Local Repository Remote Repository


git clone

git pull

Clone repository into directory


GitHub – Summary

Repository Local Remote git remote add origin URL

git branch --track branchname


Branches Local-Tracking Remote origin/branchname

Remote-Tracking git pull/push origin branch


GitHub – Deep Dive

Collaboration & Contribution


Module Content

Understanding GitHub Accounts


& Repository Types

Collaborating in GitHub
& Contributing to Open Source Projects

Creating your GitHub Portfolio Page


& More Features to Explore
Why We Use GitHub

Cloud Storage

Portfolio Page

Collaboration

Contribution
Understanding Account Types

Personal User Account Organizational Account Enterprise Account

Every GitHub user‘s Shared account for groups of Central management of multiple
user account people to collaborate GitHub accounts

Unlimited public & private Base features as for GitHub Enterprise Cloud & GitHub
repositories personal account Enterprise Server

Advanced features with


Unlimited collaborators Enterprise level only
GitHub Team/Enterprise

Base features included in “Free“ pricing plan “Enterprise“ pricing only


GitHub Security & Access

Local Git User Personal Access Token GitHub Account


GitHub account
Personal user account Part of organization
access via Git
Owner Collaborator
Member role access
access access

Repository 1 Repository 1

Repository 2 Repository 2

… …
Comparing Clone…

Clone

Account A Account B

Remote repo Direct connection

Local copy
git clone

Push to remote repo


…with Forks & Pull Requests

Fork & Pull Request

Account A Account B
Remote copy
Fork on GitHub
Remote repo Remote repo

Merge Direct connection

Local copy
Accept pull request
git clone

Remote repo Push to remote repo

Create pull request


Module Summary

GitHub
Account Types Repository Types Security

Collaboration
Collaborators Organizations Teams

Contribution & Project Management


Forks & Pull Requests Issues Projects
Applying Our Knowledge:
Food Order Project

A Real-World Example
Module Content

Creating & Using A Local Git Repository

Managing Code On Github

Collaboration: Merging & Pull Requests


Congratulations!

You Finished this Course!


Congratulations!

Working Directory Stash Tags

Staging Area Reflog Origin & Remote

Repository Merge Clone


CONGRATULATIONS!

Commits & Branches Rebase Tracking & Upstreams

You might also like