The What, Where and Why of Git

Or WTF is this Git thing?!

Paul Broadwith
  • Paul Broadwith, Glasgow, Scotland
  • 30 years in IT in financial, government, manufacturing and services sectors
  • Lead Engineer on Boxstarter and cChoco DSC Resource
  • Microsoft MVP in Cloud and Datacenter and a Microsoft Certified Trainer (MCT)
MVP Logo
Chocolatey Logo
Microsoft Certified Trainer
  • Why do you need … something like git?
  • What actually is it?
  • Git? Ugh. What is it good for? Absolutely everything. Say it again!
  • What tools do I need for git?
  • High level view of how git works;
  • What does git look like on my computer?
  • Basics of git - commits, branches and remotes;
  • Useful git commands.

What is git?

git GitHub

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

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/Distributed_version_control

Which means:

Git is a version control system which manages changes in computer files. The changes are identified by a number and can be compared, restored and merged. It is aimed at data integrity and distributed workflows.

Does that make sense?

or

Git Cloud Providers

GitHub Octocat Logo

Gitlab Logo
Bitbucket Logo

What can I use git for?

Developers, Coders and Scripters.

Writers and Authors.

Websites.

CI / CD, Runbooks, Cookbooks and Playbooks.

Good for text based files such as code, Markdown documents and CSV files - easier to detect differences.

Git can detect the changes in text files and will store only those changes.

Not so good for binary files such as Word documents, audio and video - difficult to detect differences.

Git cannot detect the changes and will store the binary file entirely.

Large files should use GitLFS.

What can git do for me?

Change history.

The who, when and what.

Undo changes made by you or others.

Collborate with others across your organisation, group or world.

Open Source community.

What tools do I need?

Chocolatey Logo

Chocolatey Home Page - https://chocolatey.org

Install Chocolatey - https://chocolatey.org/install

Git Tools

Download from https://gitforwindows.org

> choco install git -y

Git Tools

Download from https://git-scm.com/download/mac

$ brew install git

Git Tools

Ubuntu Logo
$ sudo apt-get install git
CentOS Logo
$ sudo yum install git

Visual Studio Code Logo

Visual Studio Code

https://code.visualstudio.com/docs/setup/setup-overview

> choco install vscode -y
$ brew cask install visual-studio-code
$ # See setup URL for options

Gitex Logo
GitEx

> choco install gitextensions -y

Git Logo
Git Credential Manager For Windows

> choco install git-credential-manager-for-windows -y

Gitlens Logo

> choco install vscode-git-graph -y

Gitlens Logo

> choco install vscode-gitlens -y

GitHub Logo

> choco install vscode-pull-request-github -y

posh-git

https://github.com/dahlbyk/posh-git

posh-git PowerShell Prompt

How Does Git Work?

Local repository

repository Simply think of it as a folder that can hold your projects files and folders.

The terminology repo and repository are used interchangeably.

To make a normal folder a repository, run:

git init

.git A special folder that holds all of the information git needs.

Don’t change anything in this folder as bad things will happen!

.gitignore A file containing files and folders that git should ignore.

Very useful when excluding files that you don’t want to have to skip staging.

How does git work?

The three stages of git commitment.

git add
git commit
 
   
Working Directory   Staged   Committed
 
git rm --cached
git reset

How Does Git Work?

Branching

branch A child branch is a point-in-time snapshot of it’s parent. A branch can exist on it’s own or can be brought back into the parent.

How Does Git Work?

Working With Remote Repositories

git clone
clone the repository by downloading it to your local computer.
   
   
git remote -v
Get the remote repository URL(s).

git commit
git push
Make a commit and push it to the remote repository.

   
   

Demo 1

Three stages of git commitment, branching and remotes

How Does Git Work?

Other git commands

git branch

Lists the branches in your local repository. Add -r to list remote branches.

git diff

Show changes between commits or commit and working directory.

git cherry-pick

Move individual commits.

git rebase
Move groups of commits.

What Other Resources Are There?

#AlwaysLearning

What Have We Learned?

  • Why do you need … something like git?
  • What actually is it?
  • Git? Ugh. What is it good for? Absolutely everything. Say it again!
  • What tools do I need for git?
  • High level view of how git works;
  • What does git look like on my computer?
  • Basics of git - commits, branches and remotes;
  • Useful git commands.

Congratulations!

You’re now a git too!

Questions?

https://blog.pauby.com
Paul Broadwith
@pauby
github.com/pauby
linkedin.com/in/paulbroadwith

pau.by/talks