Getting Started: What & Why?

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 46

Getting Started

What & Why?


Git & GitHub – What…

Hosting & Collaboration


Version Control System
Provider

Manage Source Code & Track


Git Repository Hosting
Changes in Code History

Mainly for Developers but not Limited to Those


… and Why?

First Draft Second Draft First Draft Second Draft

Third Draft Third Draft

Draft 4 Draft 4

Draft 20 Draft 20
Another draft Another draft

Final Final

Final Final Final Final Final Final

Copying Files Single File Only Version Management


Course Content

Optional
Git Git &
Mac Terminal & Windows
The Basics GitHub
Command Prompt

Git
Deep Dive
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


Command Prompt
(GUI)
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 Environment Text Input Interface


(“Hardware“) (“Software“)

Bash zsh (Z-Shell)


Windows Terminology

Command Prompt (cmd) PowerShell Git Bash

Initial Windows Shell New Shell (Windows 7 Bash Emulation for


Release) 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


git log
current branch

git ls-files List data in staging area


Basic Commands Summary: Commit Creation & Access

git add filename Add single file or all WD


git add . files to staging area

git commit –m “message“ Create new commit

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 branchname Go to branch

git checkout –b git switch –c Create and access new


branchname branchname branch

Bring other branch‘s


git merge otherbranch
changes to 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 Feature is finished – Implementation into


master 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)

Change single commit‘s Add specific commit to


Create merge commit
parent branch (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


git merge
commit (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
git cherry-pick
other branch
Understanding GitHub

Leaving the Local Repository


Module Content

What is GitHub?

Connecting Git & GitHub

Understanding the GitHub Basics


Git & GitHub

Hosting & Collaboration


Version Control System
Provider

Manage Source Code & Track


Git Repository Hosting
Changes in Code History
Connecting Git & Github – Create New Repository

git push

Local Repository git remote add origin URL Remote Repository

git pull

“Name of the remote machine“ or alias of the URL of the


remote repository
Connecting Git & Github – Access Existing Repository

git push

Local Repository git clone Remote Repository

git pull

Clone repository into directory


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


Local Branch
(as seen in the course)

Branch in remote location


Remote Branch
(e.g. in GitHub)

Tracking Branch

Local copy of remote branch


Remote Tracking Branch git fetch
(not to be edited)

Local reference to remote git push


Local Tracking Branch
tracking 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


Local Tracking Branch git branch –vv
their remotes

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


git branch –-track branchname
Create local tracking branch
name can be omitted origin/branchname
GitHub – Summary

Repository Local Remote git remote add origin URL

git branch --track branchname


Branches Local-Tracking Remote origin/branchname

Remote-
git pull/push origin branch
Tracking
Congratulations!

Working Directory Stash Tags

Staging Area Reflog Origin & Remote

Repository Merge Clone


CONGRATULATIONS!

Tracking &
Commits & Branches Rebase
Upstreams

You might also like