Git in Practice
Mike McQuaid
Foreword by Scott Chacon
  • September 2014
  • ISBN 9781617291975
  • 272 pages
  • printed in black & white

Shows how to make your team’s workflows simpler and more effective.

From the Foreword by Scott Chacon, Author of "Pro Git"

Git in Practice is a collection of 66 tested techniques that will optimize the way you and your team manage your development projects. The book begins with a brief reminder of the core version control concepts you need when using Git and moves on to the high-value features you may not have explored yet. Then, you'll dig into cookbook-style techniques like history visualization, advanced branching and rewriting history each presented in a problem-solution-discussion format. Finally you'll work out how to use Git to its full potential through configuration, team workflows, submodules and using GitHub pull requests effectively.

Table of Contents show full




about this book

about the cover illustartion

Part 1 Introduction to Git

1. Chapter 1 Local Git

1.1. Why do programmers use Git?

1.2. Initial setup

Technique 1 Creating a repository: git init

1.3. .git subdirectory

1.4. Creating a new commit: git add, git commit

Technique 2 Building a new commit in the index staging area: git add

Technique 3 Committing changes to files: git commit

1.4.1. Object store

1.4.2. Parent commits

Technique 4 Viewing history: git log, gitk, gitx

1.5. Rewriting history

Technique 5 Viewing the differences between commits: git diff

1.6. Diff formats

1.7. Refs

1.8. Summary

2. Remote Git

Technique 6 Adding a remote repository: git remote add

2.1. Authoritative version storage

Technique 7 Pushing changes to a remote repository: git push

Technique 8 Cloning a remote/GitHub repository onto your local machine: git clone

Technique 9 Pulling changes from another repository: git pull

Technique 10 Fetching changes from a remote without modifying local branches: git fetch

Technique 11 Creating a new local branch from the current branch: git branch

Technique 12 Checking out a local branch: git checkout

Technique 13 Pushing a local branch remotely

Technique 14 Merging an existing branch into the current branch: git merge

2.2. Merge conflicts

2.3. Rebasing

Technique 15 Deleting a remote branch

Technique 16 Deleting the current local branch after merging

2.4. Summary

Part 2 Git essentials

3. Filesystem interactions

Technique 17 Renaming or moving a file: git mv

Technique 18 Removing a file: git rm

Technique 19 Resetting files to the last commit: git reset

Technique 20 Deleting untracked files: git clean

Technique 21 Ignoring files: .gitignore

Technique 22 Deleting ignored files

Technique 23 Temporarily stashing some changes: git stash

Technique 24 Reapplying stashed changes: git stash pop

Technique 25 Clearing stashed changes: git stash clear

Technique 26 Assuming files are unchanged

Technique 27 Listing assumed-unchanged files

Technique 28 Stopping assuming files are unchanged

3.1. Summary

4. History visualization

Technique 29 Listing only certain commits

4.1. git show

Technique 30 Listing commits with different formatting

4.2. Custom output format

4.3. Releasing logs: git shortlog

4.4. The ultimate log output

Technique 31 Showing who last changed each line of a file: git blame

Technique 32 Finding which commit caused a particular bug: git bisect

4.5. Automating git bisect

4.6. Summary

5. Advanced branching

Technique 33 Merging branches and always creating a merge commit

5.1. Merge strategies

Technique 34 Resolving a merge conflict

5.2. Using a graphical merge tool

Technique 35 Resolving each merge conflict only once: git rerere

Technique 36 Creating a tag: git tag

Technique 37 Generating a version number based on previous tags: git describe

Technique 38 Adding a single commit to the current branch: git cherry-pick

Technique 39 Reverting a previous commit: git revert

Technique 40 Listing what branches contain a commit: git cherry

5.3. Summary

6. Rewriting history and disaster recovery

Technique 41 Listing all changes including history rewrites: git reflog

6.1. Avoiding and recovering from disasters

Technique 42 Resetting a branch to a previous commit: git reset

Technique 43 Rebasing commits on top of another branch: git rebase

Technique 44 Rebasing commits interactively: git rebase --interactive

Technique 45 Pulling a branch and rebasing commits: git pull --rebase

Technique 46 Rewriting history on a remote branch: git push --force

Technique 47 Rewriting the entire history of a branch: git filter-branch

6.2. Summary

Part 3 Advanced Git

7. Personalizing Git

Technique 48 Setting the configuration for all repositories

Technique 49 Setting the configuration for a single repository

7.1. Useful configuration settings

7.1.1. Colored output in Git

7.1.2. Git 2.0’s push defaults

7.1.3. Pruning branches automatically

7.1.4. Ignoring files across all repositories: global ignore file

7.1.5. Displaying help output in your web browser

7.1.6. Storing passwords in the OS X keychain

7.1.7. Storing arbitrary text in Git configuration

7.1.8. Autocorrecting misspelled commands

7.2. Sharing your Git (or other) configuration between machines

Technique 51 Showing the current branch in your terminal prompt

7.3. Summary

8. Vendoring dependencies as submodules

8.1. When are submodules useful?

Technique 52 Adding a git submodule: git submodule add

Technique 53 Showing the status of submodules: git submodule status

Technique 54 Updating and initializing all submodules: git submodule update --init

Technique 55 Running a command in every submodule: git submodule foreach

8.2. Summary

9. Working with Subversion

Technique 56 Importing an SVN repository into a Git repository

9.1. Subversion branches and tags

9.2. Subversion ignore rules

9.3. Updating a Subversion repository

9.4. Subversion authors and committers

9.5. Viewing a Subversion repository in GitX

9.6. Migrating a Subversion repository to Git

Technique 57 Committing and pushing to an SVN repository from a Git repository

9.7. Local branching and tagging

Technique 58 Accessing a GitHub repository with Subversion

9.8. Summary

10. GitHub pull requests

10.1. What are pull requests and forks?

10.2. Interacting with GitHub from the command-line: gh

Technique 59 Making a pull request in the same repository: gh pull-request

Technique 60 Making a pull request from a forked repository: gh fork

Technique 61 Merging a pull request from the same repository

Technique 62 Merging a pull request from a forked repository: gh merge

10.3. Summary

11. Hosting a repository

Technique 63 Initializing a local repository in a server hosting format: git init --bare

Technique 64 Mirroring a repository: git clone --mirror

Technique 65 Sharing a repository with other users on the same network: git daemon

Technique 66 Displaying a repository in a browser: git instaweb

11.1. Advanced Git hosting

11.2. Summary

Part 4 Git best practices

12. Creating a clean history

12.1. Writing a good commit message

12.2. Building a commit from parts of files: git add --patch

12.3. Graphically building a commit from parts of files

12.3.1. Graphically building a commit in GitX

12.3.2. Graphically building a commit in Git Gui

12.4. Avoiding whitespace issues: git diff --check

12.5. Summary

13. Merging vs. rebasing

13.1. CMake’s workflow

13.1.1. Workflow commands

13.2. Homebrew’s workflow

13.2.1. Workflow commands

13.3. CMake workflow pros and cons

13.4. Homebrew workflow pros and cons

13.5. Picking your strategy

13.6. Summary

14. Recommended team workflows

14.1. GitHub Flow

14.1.1. Pros and cons

14.2. Git Flow

14.2.1. Pros and cons

14.3. Mike Flow

14.3.1. Mike Flow Single

14.3.2. Mike Flow Multiple

14.3.3. Pros and cons

14.4. Which workflow is for you?

14.5. Summary


Appendix A: Git installation

A.1. How to install and run Git on Apple OS X

A.1.1. Installing Git on Apple OS X Mavericks or newer

A.1.2. Installing Git on Apple OS X Mountain Lion or older

A.2. How to install and run Git on Linux or Unix

A.3. How to install and run Git on Microsoft Windows

A.4. Verifying that Git has installed correctly

Appendix B: Creating a GitHub account and repositor

B.1. Signing up for a GitHub account

B.2. Creating a new repository on GitHub

Appendix C: Commented Git configuration

Appendix D: Why use version control

D.1. Handling changes

D.2. Version control workflow

D.3. Version control for programmer collaboration

index of Git methods


About the Technology

Git is a source control system, but it's a lot more than just that. For teams working in today's agile, continuous delivery environments, Git is a strategic advantage. Built with a decentralized structure that's perfect for a distributed team, Git manages branching, committing, complex merges, and task switching with minimal ceremony so you can concentrate on your code.

About the book

Git in Practice is a collection of battle-tested techniques designed to optimize the way you and your team manage development projects. After a brief overview of Git's core features, this practical guide moves quickly to high-value topics like history visualization, advanced branching and rewriting, optimized configuration, team workflows, submodules, and how to use GitHub pull requests. Written in an easy-to-follow Problem/Solution/Discussion format with numerous diagrams and examples, it skips the theory and gets right to the nitty-gritty tasks that will transform the way you work.

What's inside

  • Team interaction strategies and techniques
  • Replacing bad habits with good practices
  • Juggling complex configurations
  • Rewriting history and disaster recovery

About the reader

Written for developers familiar with version control and ready for the good stuff in Git.

About the author

Mike McQuaid is a software engineer at GitHub. He's contributed to Qt and the Linux kernel, and he maintains the Git-based Homebrew project.

combo $39.99 pBook + eBook
eBook $31.99 pdf + ePub + kindle

FREE domestic shipping on three or more pBooks

The best companion for your day-to-day journeys with Git.

Gregor Zurowski, Sotheby’s

Ready to take off your Git training-wheels? Read this book!

Patrick Toohey, Mettler-Toledo Hi-Speed

I learned more about how Git works in the first five chapters than I did in five years of using Git!

Alan Lenton, Arithmetica Ltd