Mastering Git

THE FOUR AREAS: INTRODUCTION


by scmGalaxy.com

About Me

DevOps@RajeshKumar.XYZ

Git Commands

We will focus on the Git
"way of thinking".

The Previous Training

The "Onion" Metaphor

The Previous Training (Again)

Course Overview

  • The Four Areas: Introduction

  • The Four Areas: Basic Workflow

  • The Four Areas: git reset

  • The Four Areas: Advanced Tools

  • History: Exploring the Past

  • History: Fixing Mistakes

  • Finding Your Workflow

The Command Line

The Four Areas

The Two Questions

The Three Main Areas

If you have trouble following
this section, then watch
"How Git Works" first.

The Project History

HEAD and the Current Commit

Unreachable Commits

If you could follow this
recap, then move on
with this training.

The Four Areas: Basic Workflow


The Two Questions

git rm is not the
opposite of "git add".

Git automatically finds out
when you're renaming
or moving files.

The Four Areas: git reset


Why is reset Confusing?

Commands That Move Branches


commit

merge

rebase

pull

....

Step One: Moving a Branch HEAD

Step One: Moving a Branch HEAD

Step Two: Moving Data Across the Areas

Step Two: Moving Data Across the Areas

Step Two: Moving Data Across the Areas

reset moves the current branch,
and optionally copies data from
the Repository to the other areas.

The Four Areas: More Tools


Git is a toolbox.

History: Exploring the Past


Git Commands

Summary

  • git show HEAD^

  • git show HEAD~2

  • git diff HEAD..HEAD^^

  • git blame recipes/apple_pie.txt

  • git log --graph --decorate --oneline

  • git show HEAD

History: Fixing Mistakes


Never rebase shared commits.

The Golden Rule:
never change shared history.

Be careful when you
revert merge commits.

"revert" doesn’t mean "undo".

Summary

  • git commit --amend

  • git rebase -i

  • git reflog

  • git revert HEAD

Finding Your Workflow


Distributed Workflow

This is a module about Git
workflow patterns.

What You Need to Know

  • What a Remote Is

  • Pushing to a Remote

  • Pulling from a Remote

Distributed Workflow

Peer to Peer Model

Centralized Model

Pull Request Model

Dictator and Lieutenants Model

Distribution Models

  • Peer to Peer Model

  • Centralized Model

  • Pull Request Model

  • Dictator and Lieutenants Model

Many projects use a mixed
Distribution Model.

Distributed Workflow

Stable Branch

Unstable Branch

Integration Branch

Release Branch

Feature Branch

Hotfix Branch

Branching Models

Stable and unstable branches Common Branches
  • Integration Branch

  • Release Branch

  • Feature Branch

  • Hotfix Branch

Distributed Workflow

A Few Examples of Constraints

The Elements of a Distributed Workflow

  • Distribution Model

  • Branching Model

  • Constraints

Don’t "just use GitFlow".

Don’t design a workflow.
Instead, grow it.

A Simple Workflow to Start With

  • Distribution Model

    • Centralized

  • Branching Model

    • One Integration Branch (master)

    • One Feature Branch per Feature

  • Constraints

    • Keep master stable, fix it ASAP if it breaks

    • Integrate Feature Branches every few days

    • Use merge over rebase by default

"Simple, clear purpose and principles give rise to complex and intelligent behavior.

Complex rules and regulations give rise to simple and stupid behavior."

The Four Areas

The Two Questions

Now you're thinking in Git.

Questions

Thank you!