Using Git with a GUI

THE CASE FOR GIT WITH A GUI:

MINIMIZING THE LEARNING CURVE

By scmGalaxy.com

About Me

DevOps@RajeshKumar.xyz

Command Line or GUI?

git command line

Command Line vs. GUI

Why Git?

why git

Killer Feature

git branches

Let Me Tell You a Story

git sprint code cut

Let Me Tell You a Story

git commit sprint

Let Me Tell You a Story

commit sprint git

Do You See the Problem?

do you see the git problem

This Is What happened

git this is what happened

Still Not Convinced?

git still not convinced

Git

git unprepared

Why Is It Hard to Learn Git?

why hard to learn git

Why Is It Hard to Learn Git?

  • SVN, TFS and others...
  • They are easier!
    • Simpler workf low
      • Downsides
    • Not distributed
    • Not as powertul as Git
    • Git is different

why is it hard to learn git

Why Is It Hard to Learn Git?

  • More places where your code can exist
    • Stash, local working directory, index,local repository and remote repository
    • Increases possible interactions
  • A few concepts that are hard at first
    • Merge, rebase? Fast forward merge?
  • Git internals

git

Tools - Why Is It Hard to Learn Git?

  • Many - command line being widely used
  • Can be hard - especially if used to IDE
  • Others tools are not very good
  • Atlassian SourceTree is here to help!

tools git

Git Is Hard

"Early versions of Git did require certain amount of brain power to wrap your mind around..."

Linus Torvalds

Git

Get Started

Don't Get Scared

  • Easier
  • Quicker
  • Productive

Using Git with a GUI

using git whith a gui

Why Git with a Gui?

why git with a gui

Minimize Git's Learning Curve

minimize git

Minimize Git's Learning Curve

git learning curve

Minimize Git's Learning Curve

gits learning curve

Demo

git source tree

Atlassian Source Tree

Perfect for Beginners

  • GUI
  • Much easier than command line
  • Pareto's Law (80/20 Rule)
  • Most likely does everything you need
  • Easy... Simple...
  • Smoother learning curve
  • Git feel familiar from day 1

Atlassian Source Tree

Powerful Enough for Experts

  • Terminal
  • Extensible
  • Custom Actions
  • Review outgoing/incoming changesets
  • Cherry-pick between branches
  • Patch handling, (interactive) rebase, stash, shelve, and much more

Atlassian Behind Source Tree

git atlassian behind source tree

Atlassian Behind Source Tree

 atlassian behind source tree git

How Do I Get Source Tree?

git how do i get source tree

Free!

source tree git

Takeaway

git takeaway

Mechanics of Using Git (With a GUI)

git 101

Beyond Learning Git's Commands & Actions

beyond learning gits commands and action.jpg

Git 101: What You Need to Get Started Work

git 101: what you need to get started work

Quick Tour Around Atlassian Source Tree

git quick tour around atlassian source tree

Menus, Dropdown and Commands

git menus dropdown and commands
git of source tree
using git for source tree
source tree for git
using git of sour tree

icons

git icons
source tree new folder using git
source tree solrnet git
source tree pending file git
additional parameters source tree git

Options

/git options

Options

/using git options

Options

/git aunthentication options

Getting the Code

git getting the code

Basic Concept: Clone Out vs. Fork

git basic concept clone out vs work

Fork

git fork

Clone Add Create Repository

Source Tree

git clone repository source tee

Clone

git clone

Cloning: Bit Bucket with Source Tree

git cloning bit bucket with source tree

Organizing Your Workspace

git organizing your workspace

Staying Up To Date

Fetch
  • Get remote changes
  • Into local repository
  • Does not affect your code
  • No merge takes place
  • Let's you inspect before merging
Pull
  • Fetch + Merge
  • Changes into working copy
  • Your local branches will be updated
  • Let's you inspect before merging

Staying Up To Date

git stying up to date

Demo

Getting the Code

Development Line of Work
Understanding Branches
git understanding branches

Branching

git branching

Branches

git for branches

Where Can I Branch

git where can i branch

Demo

Branching

I Coded Now What?

git i coded now what

I Coded - Now What?

using git i coded now what

The Three States of Files

git the three states of files

Sections of a Git Project

sections of a git project

Preparing the Commit: The Index

  • Staging area
  • Why not directly?
  • Hunks: Add files or pieces of files
  • Review
  • Preparation area
  • To be included in next commit
  • Resolve conflicts

git preparing the commit the index

Whistle While You Work

git whistle while you work

Discarding Changes

  • Mistakes happen
  • Discard changes since last commit
  • Careful when using it
  • Is a destructive operation

git discarding changes

Discarding changes

git discarding changes source tree

Stash

  • Code mess?
  • But need to save changes
  • Without committing
  • Like a shelveset in TFS
  • Can be reapplied later

git stash

Stash

git stash source tree

Reapplying a Stash

  • Get back that piece of code
  • From your Stash
  • Into Working Copy

git reapplying a stash

Demo

Discard and Stash

Ignoring Files

May not want to commit all files

.gitigncre

Exact name Pattern
Path Extension

This repository OR All repositoriesi

Ignoring Files

git ignoring files
testing gitignore

Demo

Ignoring Files

Staging & Hunks

git staging and hunks
git source tree uncommitted changes

Why Are I lunks Amazing?

git why are i lunks amazing
git source tree solrnet
git source tree solrnet uncommitted chages
git source tree show remote branches

Demo

Staging and Hunks

Commit Messages

git commit messages

Seven rules of a great Git commit message

  • Separate subject from body with a blank line
  • Limit the subject line to 50 characters
  • Capitalize the subject line
  • Do not end the subject line with a period
  • Use the imperative mood in the subject line
  • Wrap the body at 72 characters
  • Use the body to explain what and why vs. how

:hris Beams, Tim Pope, Peter H utterer, Git Pro book and posts in GitHub projects...

A Great Commit Message

If applied, this commit will

git a great commit message

Commit

Save the staged snapshot to the Droject repository

git commit

Commit

git commit source tree

Demo

Commit

Merging

  • Join two or more
  • Development branches
  • Part of the workflow
  • Work, commit, and...
  • Merge a branch
  • (Or many)

git merging

Pull First

  • Your responsibility to avoid conflicts
  • Pull first
    • Fetch and Merge into your branch
  • And then merge
    • Pull Request

git pull first

Demo

Merging

Push

  • Pushed to remote repository
  • Deployed, reviewed, integrated,
  • Upload: Commits, branches, tags,
  • Hooks
  • Avoid conflicts
  • Pull Request

git push
git source tree push solrnet

Demo

Push

Merge Conflicts

  • Changes in same area
  • In different branches
  • In the same line or lines
  • Or edit a file that is deleted elsewhere
  • Merge conflict
  • Which one to pick?
  • Resolve

git merge conflicts

Conflicts

Mine or Theirs

  • Pick one of the changes
  • One change is latest
  • Careful not breaking other branch

Resolve Manually

  • Manual resolution required
  • Pieces of both changes may be required
  • Make sure both branch changes work
  • Leverage external tool
source tree gitgraph

Demo

Conflicts

Pull Request

  • Or as I call it
  • Here's My Code
  • Please Take It

git pull request
git source-tree sorner sorted by path

Pull Request

  • Method of submitting code
  • To a project
  • Distributed source control
  • Review changes
  • Collaborate and improve
  • Before merge
  • Accepted or rejected

using git pull request
git comparing changes
git showing 1 changed file whith 11 addinatinal and 1 dletion
git open a pull request
git include explanation on facet limit in facets
git some checked have comleted yet

And After The Pull Request...

  • You may need to wait for merge
  • Maintainer needs to OK
  • Especially in open source
    • Some are pretty quick!
  • Sometimes you need to improve
  • It is collaboration time

git and after the pull request

Once You Get The OK...

git once you get the ok

Demo

Pull Requests

Cleaning Up

Delete branch after merging

git cleaning up

Demo

Deleting Branches

Cleaning Up

Takeaway

using git takeaway

Git: To the Next Level (With a GUI)

"Small commits allow for big wins"

Cherry Pick

  • Really useful command
  • N'love single(or specific) commit(s)
  • From one branch to another
  • Why not a merge?
    • You may not want everything
    • Incompatibilities<
    • Specific feature in out of date branch

git cherry pick

Demo

Cherry Pick

Blame

  • Helps determine who made changes
    • And why
  • History tells you files and changes Last modification for each line Revision and author Known as annotate in TFS

git blame

Search

 git search

Demo

Blame and Search

Merging vs. Rebasing

 git merging vs. rebasing

Golden Rule of Rebasing

  • When NOT to do it: public branches
  • Rebase master into your feature branch
  • Happens in your repository
  • Confusion for everyone
  • you insist: most likely force push required
  • ways think
    • "Is anyone else looking at this branch?"

Golden Rule of Rebasing

git golden rule of rebasing

Merging vs. Rebasing

git merging vs. rebasing

Demo

Merging vs. Rebasing

Fast Forward Merge

  • Special case
  • Branch... Work...
  • Merge
  • No commits in master?
  • Fast forward merge!
  • merge commit
  • Just like rebase
  • [Optional]

Fast Forward Merge

git fast forward merge

Demo

Fast Forward Merge

Understanding Tags

git understanding tags

Understanding Tags

using git understanding tags

Demo

Tagging

Detached Head

  • Git→ Direct acyclic graph of commits
    • Fancy name for a tree of commits
  • Work in Branches
    • Checkout
  • Checkout a commit?
  • No Head
  • This is called a Detached Head
  • And it will give you a headache
  • There is a way

Detached Head

git detached head

Demo

Detached Head

Rewriting History

  • Git is designed to never lose a change
  • But...
  • It is also really powerful
  • Rewrite history
  • Usually only on your own to prepare a push
  • Rebase interactively
  • Disclaimers:
    • Not recommended as normal action
    • Don't amend public commits

Rewriting History

git rewriting history

Rebase Interactively

git rebase interactively

Reordering Commits

  • May need to reorder your commits
  • SourceTree → drag and drop
  • Not done
  • Until you click OK
  • And get confirmation

Reordering Commits

git reordering commits

Demo

Reordering Commits

Editing Commit Comment

  • May need to change commit comment
  • Rewriting history
  • Dead easy with SourceTree
  • Careful: on changes not pushed yet
  • Tip:
    • Change author is possible too!
    • git filter-branch

Editing Commit Comment

git editing commit comment

Amend Commit

  • Besides change comment and order
  • Change content (snapshot)
    • Adding or removing
  • Disclaimer: Changes SHA1
  • Select Amend latest commit
  • From commit options

Amend Commit

git amend commit

Demo

Editing and Amending Commits

Squash Commits

  • "Commit early, commit often"
  • End up with lots of commits
  • Lot of them being WIP (work in progress)
  • Squash multiple commits
  • Rebase interactively
  • Clean history
  • Overview as commit message
    • "Includes completed slides for module 3"

Debate: To squash or not to squash...

Squash Commits

git squash commits

Squash Commit Messages

  • Not about file revisions
  • It is about "Qverview"
  • What bug is fixed?
  • What feature done?

git squash commit messages

Demo

Squash Commits

Deleting a Commit

  • Preferred to only add in Git
  • But delete is possible
  • Careful
  • Try to avoid deleting
  • Rebase interactively

Deleting a Commit

git deleting a commit

Deleting a Commit - Reset

git deleting a commit reset

Deleting a Commit - Reset

using git deleting a commit reset

Demo

Deleting Commits

Reverse Commit

  • Mistakes can be made
    • Let's avoid deleting commits
  • Reverse commit instead!
  • Revert
    • Safe method
  • Undo committed snapshot
  • By creating a new commit

Reverse Commit

git reverse commit

Reverse Commit

using git reverse commit

Demo

Reverse Commit

Recover Deleted Commit

  • You HARD deleted a commit
  • Panic!
  • Not all is lost
  • No need to start crying!
  • Dangling commit
  • Open terminal and let's get advanced
  • You just need the SHA1 to get it back
    • fb6ac4872fcbaec627dedela2l b626ecbaa89eOO [fb6ac48]

Recover Deleted Commit

git recover deleted commit

Recover Deleted Commit

using git recover deleted commit

Demo

Recovering Deleted Commits

Custom Actions

  • Not everything available in SourceTree
  • Extend range of actions
  • Creating scripts or commands
  • Defined variables
  • PowerShell, bash or Git command
  • Harness full power of Git

Recover Deleted Commit

git custom actions

Demo

Custom Actions

Takeaway

using git takeaway

Branching Strategies For Every Occasion

Branching Strategies for Every Occasion

git branching strategies for every occasion

Starting with Git: Branching 101

starting with git: branching 101

Git Workflows

git workflows

Centralized Worktlow

  • Easiest way to get started
  • Do what you know
  • Treat as centralized repository
  • Developers pull and push directly
  • Just like SVN or TFS
  • No changes needed in how you work
  • Quicker adoption
  • Git = Advantages!

Centralized Worktlow

git centralized worktlow

Centralized Workflow: Advantages with Git

centralized workflow advantages with git

Centralized Workflow: Working

git centralized workflow working

Centralized Worktlow: Work Goes On

  • Developers keep working
  • Git will not allow overriding commits
  • Get all changes before Push
  • Resolve Conflicts and then Push

Centralized Worktlow: Work Goes On

git centralized worktlow work goes on

There is a secret to making it all work

git there is a secret to making it all work

Rebasing is the Key

git rebasing is the key

Centralized Workflow: Rebasng

  • Add your changes in a linear way to origin/master
  • Focused changes
  • Clean history

git centralized workflow rebasng

Centralized Workflow

git centralized workflow

Problem with Centralized Workflow

git problem with centralized workflow

Problem with Centralized Workflow

  • Code in master always deployment ready?
  • Work in progress on a feature?
  • Collaborating on a feature?
  • Prevent broken code in master?
  • Caveats present in other source control systems

git problem with centralized workflow

Feature Branch Workflow

git feature branch workf low

Feature Branch Workflow

using git feature branch workflow

Integration: BitBucket, Jira & Bamboo

git integration bitbucket jira and bamboo

Feature Branch: A Branch for Every Feature

git feature branch a branch for every feature

Pushing Feature Branches

Merge

  • Merge
  • Incorporate changes
  • From current feature branch
  • Into master branch
  • Required: Feature branch up to date
  • Conflicts resolved
  • Merge commit
  • Or
  • Fast-forward merge

Pushing Feature Branches

Pull Request

  • Request to merge
  • Permissions
  • Notifications
  • Collaboration
  • Code review (complete diff)
  • Discussion proposed feature
  • Approved - Merged!
  • [Capabilities vary Bitbucket vs GitHub vs ...]

Gitflow Workflow

A successful Git branching model

In this post I present the develocmeni model that rye introduced for some of my projects (both a: work and private about a year ago, and which has turned ou to be very successful I've been meaning to write about it for a while now, but I've never really found the time to do so thoroughly, until now. I won't talk about any of the projects' details, merely about :he branching strategy and release management

http://nvie.com/posts/a-successful-git-branching-model/

Feature Branch Workflow

feature branch workflow

Gitflow: Brilliant!

That's what I think...

Gitflow Workflow

  • Great complex projects
  • As well as small projects
  • Brilliant organization of your work stream
  • Simplifies complex source code management
  • Feature / Hotfix / Release
  • Parallel
  • Distinction: Development vs. Production Ready
  • How did I lived without it?

Gitflow Workflow: Main Branches

master

  • origin/master HEAD → Production Branch
  • Production Release:
    • Merge stable develop into master via Release Branch and Tag

develop

  • origin/develop HEAD → Integration Branch
  • Latest dev changes
  • Nightly build
  • Only merge completed features

Infinite lifetime!

Gitflow Workflow: Supporting Branches

Teams can work in parallel

Without much disruption

gitfiow workflow supporting branches

Feature Branches

  • A branch for every feature
  • Start by branching develop
    • Exists while in development
  • Recommended in local repo
    • ↑origin: backup | collaboration
  • Ready?
    • Merge when done a.k.a. "Topic" branches


  • Branch off from
    • develop
  • Merge back into
    • develop
  • Can be named anything except:
    • master, develop,
    • re/ease-*, hotfix-*

Release Branches

  • Support preparation production release
    • Branch almost production ready
    • Can work on minor bug fixes
    • Update metadata (version info)
  • Work can continue on develop
  • Ready?
    • Merge into master
    • Tag release and delete branch


  • May branch off from:
    • develop
  • Must merge back into:
    • develop and master
  • Branch naming convention:
    • release-*

Hotfix Branches

  • Prepare release (Unplanned! — React)
  • Fix a bug (or a few)
    • While team keeps working
  • Ready?
    • Update metadata
    • Merge into master & develop
      • Except if release branch exists
      • Merge into release branch
    • Delete branch


  • May branch from
    • master
  • Must merge back into
    • develop and master
  • Potentially release
  • Naming convention
    • hotfix- *

Using GitFlow from SourceTree

using gitfiow from sourcetree

Demo

Gitflow Workflow

From Source Tree

Forking WorkfIow

  • Important Difference
  • Besides main repository
  • Every developer (or team)
    • Server side repository (usually public)
    • Local (private)
  • Push to their own server side repo
  • Pull requests to main repository
  • Perfect for open source!
  • As well as enterprise

Forking Workflow

git forking workflow

Forking from Repository

git forking from repository

Repository Might Keep Evolving

git repository might keep evolving

Forking Workflow

using git forking workflow

Dictator and Lieutenants Workflow

  • Linux uses this workflow
  • Benevolent dictator:
    • Linus Torvalds
  • Blessed repository
    • Developers pull from here
  • Developers
    • Rebase on master
  • Lieutenants merge into their branch
  • Dictator merges Lieutenants’ branches
  • Dictator pushes to blessed repository

Dictator and Lieutenants Workflow

 git dictator and lieutenants workflow

Takeaway

 git for takeaway

Final Takeaway

Takeaway

using git for takeaway

Takeaway

 using git with takeaway

Questions?

git-questions

Thank You!

tml>