Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals -...

62
GIT FUNDAMENTALS Open up a world of community and collaboration Paul Broadwith @pauby https://blog.pauby.com

Transcript of Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals -...

Page 1: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

GIT FUNDAMENTALSOpen up a world of community and collaboration

Paul Broadwith@pauby

https://blog.pauby.com

Page 2: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

WHO AM I?

• Senior Technical Engineer @ Chocolatey Software

• 25+ years in IT in the defence, government, financial services and nuclear industry sectors.

• Scottish PowerShell & DevOps User Group Founder

Paul Broadwith

Page 3: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...
Page 4: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

QUESTIONS AT END –MAYBE?

Page 5: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

QUESTIONS ANYTIME

Page 6: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

AGENDA

• What actually is Git?

• What tools do I need for Git?

• Who is using Git and why do I need to use it?

• How does Git work?

• Essential Git commands you need to know!

Page 7: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

WHO IS THIS AIMED AT?

Level 100

Page 8: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...
Page 9: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

Git

is not

GitHub

Page 10: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

WHAT IS GIT?

Page 11: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

WHAT IS GIT?│WHAT IS IT?

Wikipedia defines Git as:

Git is a version control system for tracking changes in computer files and coordinating work on those files among multiple people. It is primarily used for source code management in software development,but it can be used to keep track of changes in any set of files. As a distributed revision control system it is aimed at speed, data integrity, and support for distributed, non-linear workflows.

https://en.wikipedia.org/wiki/Git

Page 12: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

WHAT IS GIT?│WHAT IS IT?

Which means Git is:

Git is a version control system for tracking changes in computer files. It is aimed at speed and data integrity.

Page 13: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

WHAT IS GIT?│WHAT IS IT?

Wikipedia defines Version Control System as:

… version control is the management of changes to documents, computer programs, large web sites, and other collections of information. Changes are usually identified by a number or letter code, termed the "revision number“ … Each revision is associated with a timestamp and the person making the change. Revisions can be compared, restored, and with some types of files, merged.

https://en.wikipedia.org/wiki/Version_control

Page 14: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

WHAT IS GIT?│WHAT IS IT?

Which means a version control system is:

Version control is the management of changes to collections of information. Changes are identified by a number associated with a timestamp and the person making the change.

Page 15: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

WHAT TOOLS DO I NEED?

Page 16: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

TOOLS│CHOCOLATEY PACKAGE MANAGER

https://chocolatey.org

https://chocolatey.org/install

Page 17: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

TOOLS│REQUIRED SOFTWARE

http://gitforwindows.org/

Git Tools

> choco install git -y

Page 18: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

TOOLS│RECOMMENDED SOFTWARE

Git Credential Manager For Windows

Git Extensions

GitHub Pull Requests

posh-git

PSGit

Page 19: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

WHO USES GIT?

Page 20: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

WHO USES GIT?│COMPANIES & PROJECTS YOU KNOW

Page 21: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

WHO USES GIT?│PROVIDERS & SOFTWARE

Page 22: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

WHO USES GIT?│MICROSOFT WINDOWS & GVFS

8421

2500

4352

1760

Code Pushes (per day)

Pull Requests (per day)

Active Branches

Windows Builds (per day)

https://blogs.msdn.microsoft.com/bharry/2017/05/24/the-largest-git-repo-on-the-planet/

As at May 2017 (Using GVFS)

Page 23: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

WHO USES GIT?│VISUAL STUDIO CODE ON GITHUB

1561

717

104

49

Issues

Commits

Pull Requests

Authors

16 December 2017 to 16 January 2018

Page 24: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

WHO USES GIT?│DSCRESOURCES REPOSITORY

https://blogs.msdn.microsoft.com/powershell/2018/09/13/desired-state-configuration-dsc-planning-update-september-2018/

Since 1 January 2018

475 Pull Requests

300 Closed Issues

Page 25: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

WHO USES GIT?│PEOPLE LIKE YOU

Writers Websites

Developers, Coders& ScriptersCI / CD,

Runbooks,Cookbooks

Page 26: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

WHY DO I NEED TO USE GIT?

Page 27: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

WHY DO I NEED TO USE GIT?│POWERSHELL DEV

I write PowerShell …

… I’m not a developer

Page 28: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

WHY DO I NEED TO USE GIT?│POWERSHELL DEV

If you write code …

… you are a developer

Page 29: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

WHO USES GIT?│2017 GITHUB USE

https://octoverse.github.com/

47 Million Pull Requests

24 Million Developers

25.3 Million Active Repositories

1 Billion Commits

Page 30: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

WHO USES GIT?│GITHUB REPO BY LANGUAGE

3,027,077

1,433,985

675,803

33,012

Javascript

Python

C#

PowerShell

12 September 2018

Page 31: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

WHY DO I NEED TO USE GIT?│GIT HAS YOUR BACK

ChangeHistory

UndoMistakes Collaborate

CI / CD

Open Source

Page 32: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

WHY DO I NEED TO USE GIT?│DON’T HIDE YOUR CODE

Page 33: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

WHY DO I NEED TO USE GIT?│BEARDY DEV

Page 34: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

HOW DOES GIT WORK?3 Stages

Page 35: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

HOW DOES GIT WORK?│3 STAGES

Unstaged Staged Committed

> git status> git add <. | FILES>

> git commit –m ‘Message’

Change source files

Stage changed files

Commit changes

Page 36: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

HOW DOES GIT WORK?│5 FUNDAMENTALS OF GIT

commit

pull requests

repository

fork *

branches

Page 37: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

HOW DOES GIT WORK?│REPOSITORY

Just a folder where you store your project files

Repository / Repo – terminology - both used

myproject

Page 38: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

HOW DOES GIT WORK?│SPECIAL REPOSITORY FILES

.git

History, index and other management files for Git

File and folder name patterns that Git should ignore

.gitignore

HIDDENDON’T

TOUCH!

Page 39: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

HOW DOES GIT WORK?│BRANCHES

master branch

update-doc branch

dev branch

fix-memory-leak branch

Page 40: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

HOW DOES GIT WORK?│PULL REQUEST

Allows review and discussion around those changes.

master branch

update-doc branch

Lets others know about a change you have made.

Page 41: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

HOW DOES GIT WORK?│COMMIT

When one or more changes have been applied to a branch, it is called a …

Committed

> git commit –m ‘Message’

Commit changes

… commit

Page 42: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

HOW DOES GIT WORK?│FORK (vs. CLONE)

cool-project my/cool-project

cool-project fork

repository link

Forking a repo is simply creating a linked copy of that repository. The link allows changes to be pulled or pushed to the original repository.

cool-project clone

Without the link it’s just a clone of the repository.

Page 43: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

ESSENTIAL GIT COMMANDS YOU NEED TO KNOW!

Page 44: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

ESSENTIAL GIT COMMANDS?│8 OF THEM

status?add+

pull

clone push

checkout

commit

remote

Page 45: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

HOW GIT WORKS│GIT STATUS

Pull

> git status

Screenshot of status

Page 46: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

HOW GIT WORKS│GIT CLONE

Pull

> git clone <URL>

Page 47: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

HOW GIT WORKS│GIT PULL

Pull

> git pull

Page 48: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

HOW GIT WORKS│GIT ADD

Pull

> git add <. | FILES>

Page 49: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

HOW GIT WORKS│GIT COMMIT

Pull

> git commit –m ‘<MESSAGE>’

Page 50: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

HOW GIT WORKS│GIT PUSH

Push

> git push

Page 51: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

HOW GIT WORKS│GIT CHECKOUT

Push

> git checkout [-b] <BRANCH>

Page 52: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

DEMO 1

Page 53: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

HOW GIT WORKS│STANDARD GIT CYCLE

Push

Commit

Pull

> git pull > git add .> git commit –m “Initial commit”

> git push

Page 54: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

DEMO 2

Page 55: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

HOW DOES GIT WORK?│FORK REPOSITORY FLOW

origin/master branch

remove-aliases branch created fromorigin/master

commit code

submit pull request

remove-aliases branch merged toupstream/master

review changes

> git checkout –b dev> git add .> git commit –m “msg”> git push

upstream/master branch

Page 56: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

ESSENTIAL GIT COMMANDS?│USEFUL COMMANDS

reset?

fetch merge

rebase?

stash

Page 57: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

AGENDA QUESTIONS

• What actually is Git?

• What tools do I need for Git?

• Who is using Git and why do I need to use it?

• How does Git work?

• Essential Git commands you need to know!

Git is a Version Control System

Git Tools, Credential Manager, Git Extensions (& Git Lens?)

EVERYBODY and it will help you write better code!

5 fundamentals, 3 stages

8 commands

Page 58: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...
Page 59: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

QUESTIONS?

Page 60: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

Congratulations!

You’re now a git !git

Page 61: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

QUESTIONS?

Page 62: Git Fundamentals - Paul Broadwith - pauby.com€¦ · Microsoft PowerPoint - Git Fundamentals - Paul Broadwith.pptx Author: Paul Created Date: 9/27/2018 10:00:51 AM ...

pauby.com

@pauby

github.com/pauby

linkedin.pauby.com

Paul Broadwith

pau.by/talks