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?
Why Git?
Killer Feature
Let Me Tell You a Story
Let Me Tell You a Story
Let Me Tell You a Story
Do You See the Problem?
This Is What happened
Still Not Convinced?
Git
Why Is It Hard to Learn Git?
Why Is It Hard to Learn Git?
- SVN, TFS and others...
- They are easier!
- Simpler workf low
- Not distributed
- Not as powertul as Git
- Git is different
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
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!
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
Why Git with a Gui?
Minimize Git's Learning Curve
Minimize Git's Learning Curve
Minimize Git's Learning Curve
Demo
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
Atlassian Behind Source Tree
How Do I Get Source Tree?
Free!
Takeaway
Mechanics of Using Git (With a GUI)
Beyond Learning Git's Commands & Actions
Git 101: What You Need to Get Started Work
Quick Tour Around Atlassian Source Tree
Menus, Dropdown and Commands
icons
Getting the Code
Basic Concept: Clone Out vs. Fork
Fork
Clone Add Create Repository
Source Tree
Clone
Cloning: Bit Bucket with Source Tree
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
Development Line of Work
Understanding Branches
Branching
Branches
Where Can I Branch
I Coded Now What?
I Coded - Now What?
The Three States of Files
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
Whistle While You Work
Discarding Changes
- Mistakes happen
- Discard changes since last commit
- Careful when using it
- Is a destructive operation
Discarding changes
Stash
- Code mess?
- But need to save changes
- Without committing
- Like a shelveset in TFS
- Can be reapplied later
Stash
Reapplying a Stash
- Get back that piece of code
- From your Stash
- Into Working Copy
Ignoring Files
May not want to commit all files
.gitigncre
Exact name |
Pattern |
Path | Extension |
This repository OR All repositoriesi
Ignoring Files
Staging & Hunks
Why Are I lunks Amazing?
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
Commit
Save the staged snapshot to the Droject repository
Commit
Merging
- Join two or more
- Development branches
- Part of the workflow
- Work, commit, and...
- Merge a branch
- (Or many)
Pull First
- Your responsibility to avoid conflicts
- Pull first
- Fetch and Merge into your branch
- And then merge
Push
- Pushed to remote repository
- Deployed, reviewed, integrated,
- Upload: Commits, branches, tags,
- Hooks
- Avoid conflicts
- Pull Request
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
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
Pull Request
- Or as I call it
- Here's My Code
- Please Take It
Pull Request
- Method of submitting code
- To a project
- Distributed source control
- Review changes
- Collaborate and improve
- Before merge
- Accepted or rejected
And After The Pull Request...
- You may need to wait for merge
- Maintainer needs to OK
- Especially in open source
- Sometimes you need to improve
- It is collaboration time
Once You Get The OK...
Cleaning Up
Delete branch after merging
Demo
Deleting Branches
Cleaning Up
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
Blame
- Helps determine who made changes
History tells you files and changes
Last modification for each line
Revision and author
Known as annotate in TFS
Search
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
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
Understanding Tags
Understanding Tags
Detached Head
- Git→ Direct acyclic graph of commits
- Fancy name for a tree of commits
- Work in Branches
- Checkout a commit?
- No Head
- This is called a Detached Head
- And it will give you a headache
- There is a way
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
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
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
Amend Commit
- Besides change comment and order
- Change content (snapshot)
- Disclaimer: Changes SHA1
- Select Amend latest commit
- From commit options
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
Squash Commit Messages
- Not about file revisions
- It is about "Qverview"
- What bug is fixed?
- What feature done?
Deleting a Commit
- Preferred to only add in Git
- But delete is possible
- Careful
- Try to avoid deleting
- Rebase interactively
Deleting a Commit
Deleting a Commit - Reset
Deleting a Commit - Reset
Reverse Commit
- Mistakes can be made
- Let's avoid deleting commits
- Reverse commit instead!
- Revert
- Undo committed snapshot
- By creating a new commit
Reverse Commit
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
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
Takeaway
Branching Strategies For Every Occasion
Branching Strategies for Every Occasion
Starting with Git: Branching 101
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
Centralized Workflow: Advantages with 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
There is a secret to making it all work
Rebasing is the Key
Centralized Workflow: Rebasng
- Add your changes in a linear way to origin/master
- Focused changes
- Clean history
Centralized Workflow
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
Feature Branch Workflow
Feature Branch Workflow
Integration: BitBucket, Jira & Bamboo
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
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
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
- Merge back into
- 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:
- Must merge back into:
- Branch naming convention:
Hotfix Branches
- Prepare release (Unplanned! � React)
- Fix a bug (or a few)
- Ready?
- Update metadata
- Merge into master & develop
- Except if release branch exists
- Merge into release branch
- Delete branch
- May branch from
- Must merge back into
- Potentially release
- Naming convention
Using GitFlow 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
Forking from Repository
Repository Might Keep Evolving
Forking Workflow
Dictator and Lieutenants Workflow
- Linux uses this workflow
- Benevolent dictator:
- Blessed repository
- Developers pull from here
- Developers
- Lieutenants merge into their branch
- Dictator merges Lieutenants� branches
- Dictator pushes to blessed repository
Dictator and Lieutenants Workflow
Takeaway
Takeaway
Takeaway
Questions?