Home Page Icon
Home Page
Table of Contents for
Table of Contents
Close
Table of Contents
by Jakub Narębski, Rasmus Voss, Aske Olsson, Ferdinando Santacroce
Git: Mastering Version Control
Git: Mastering Version Control
Table of Contents
Git: Mastering Version Control
Git: Mastering Version Control
Credits
Preface
What this learning path covers
What you need for this learning path
Who this learning path is for
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
I. Module 1
1. Getting Started with Git
Installing Git
Running our first Git command
Setting up a new repository
Adding a file
Commit the added file
Modify a committed file
Summary
2. Git Fundamentals – Working Locally
Repository structure and file status life cycle
The working directory
File statuses
The staging area
Unstaging a file
The time metaphor
The past
The present
The future
Working with repositories
Unstaging a file
Viewing the history
Anatomy of a commit
The commit snapshot
The commit hash
Author, e-mail, and date
Commit messages
Committing a bunch of files
Ignoring some files and folders by default
Highlighting an important commit – Git tags
Taking another way – Git branching
Anatomy of branches
Looking at the current branches
Creating a new branch
Switching from branch to branch
Understanding what happens under the hood
A bird's eye view to branches
Typing is boring – Git aliases
Merging branches
Merge is not the end of the branch
Exercises
Exercise 2.1
What you will learn
Scenario
Results
Exercise 2.2
What you will learn
Scenario
Results
Deal with branches' modifications
Diffing branches
Using a visual diff tool
Resolving merge conflicts
Edit collisions
Resolving a removed file conflict
Keeping the edited file
Resolving conflicts by removing the file
Stashing
Summary
3. Git Fundamentals – Working Remotely
Working with remotes
Setting up a new GitHub account
Cloning a repository
Uploading modifications to remotes
What do I send to the remote when I push?
Pushing a new branch to the remote
The origin
Tracking branches
Downloading remote changes
Checking for modifications and downloading them
Applying downloaded changes
Going backward: publish a local repository to GitHub
Adding a remote to a local repository
Pushing a local branch to a remote repository
Social coding – collaborate using GitHub
Forking a repository
Submitting pull requests
Creating a pull request
Summary
4. Git Fundamentals – Niche Concepts, Configurations, and Commands
Dissecting the Git configuration
Configuration architecture
Configuration levels
System level
Global level
Repository level
Listing configurations
Editing configuration files manually
Setting up other environment configurations
Basic configurations
Typos autocorrection
Push default
Defining the default editor
Other configurations
Git aliases
Shortcuts to common commands
Creating commands
git unstage
git undo
git last
git difflast
Advanced aliases with external commands
Removing an alias
Aliasing the git command itself
Git references
Symbolic references
Ancestry references
The first parent
The second parent
World-wide techniques
Changing the last commit message
Tracing changes in a file
Cherry picking
Tricks
Bare repositories
Converting a regular repository to a bare one
Backup repositories
Archiving the repository
Bundling the repository
Summary
5. Obtaining the Most – Good Commits and Workflows
The art of committing
Building the right commit
Make only one change per commit
Split up features and tasks
Write commit messages before starting to code
Include the whole change in one commit
Describe the change, not what you have done
Don't be afraid to commit
Isolate meaningless commits
The perfect commit message
Writing a meaningful subject
Adding bulleted details lines, when needed
Tie other useful information
Special messages for releases
Conclusions
Adopting a workflow – a wise act
Centralized workflows
How they work
Feature branch workflow
GitFlow
The master branch
Hotfixes branches
The develop branch
The release branch
The feature branches
Conclusion
The GitHub flow
Anything in the master branch is deployable
Creating descriptive branches off of the master
Pushing to named branches constantly
Opening a pull request at any time
Merging only after a pull request review
Deploying immediately after review
Conclusions
Other workflows
The Linux kernel workflow
Summary
6. Migrating to Git
Before starting
Prerequisites
Working on a Subversion repository using Git
Creating a local Subversion repository
Checking out the Subversion repository with svn client
Cloning a Subversion repository from Git
Setting up a local Subversion server
Adding a tag and a branch
Committing a file to Subversion using Git as a client
Using Git with a Subversion repository
Migrating a Subversion repository
Retrieving the list of Subversion users
Cloning the Subversion repository
Preserving the ignored file list
Pushing to a local bare Git repository
Arranging branches and tags
Renaming the trunk branch to master
Converting Subversion tags to Git tags
Pushing the local repository to a remote
Comparing Git and Subversion commands
Summary
7. Git Resources
Git GUI clients
Windows
Git GUI
TortoiseGit
GitHub for Windows
Atlassian SourceTree
Cmder
Mac OS X
Linux
Building up a personal Git server with web interface
The SCM Manager
Learning Git in a visual manner
Git on the Internet
Git community on Google+
GitMinutes and Thomas Ferris Nicolaisen's blog
Ferdinando Santacroce's blog
Summary
II. Module 2
1. Navigating Git
Introduction
Git's objects
Getting ready
How to do it...
The commit object
The tree object
The blob object
The branch
The tag object
How it works...
There's more...
See also
The three stages
Getting ready
How to do it…
How it works…
See also
Viewing the DAG
Getting ready
How to do it...
How it works...
See also
Extracting fixed issues
Getting ready
How to do it...
How it works...
There's more...
Getting a list of the changed files
Getting ready
How to do it...
How it works...
There's more...
See also
Viewing history with Gitk
Getting ready
How to do it...
How it works...
There's more...
Finding commits in history
Getting ready
How to do it...
How it works...
There's more...
Searching through history code
Getting ready
How to do it...
How it works...
There's more...
2. Configuration
Configuration targets
Getting ready
How to do it...
How it works...
There's more...
Querying the existing configuration
Getting ready
How to do it...
How it works...
There's more...
Templates
Getting ready
How to do it...
How it works...
A .git directory template
Getting ready
How to do it...
How it works...
See also
A few configuration examples
Getting ready
How to do it...
Rebase and merge setup
Expiry of objects
Autocorrect
How it works...
There's more...
Git aliases
Getting ready
How to do it...
How it works...
There's more...
The refspec exemplified
Getting ready
How to do it...
How it works...
3. Branching, Merging, and Options
Introduction
Managing your local branches
Getting ready
How to do it…
How it works…
There's more...
Branches with remotes
Getting ready
How to do it…
There's more...
Forcing a merge commit
Getting ready
How to do it...
There's more…
Using git rerere to merge known conflicts
How to do it…
There's more...
The difference between branches
Getting ready
How to do it…
There's more…
4. Rebase Regularly and Interactively, and Other Use Cases
Introduction
Rebasing commits to another branch
Getting ready
How to do it…
How it works
Continuing a rebase with merge conflicts
How to do it
How it works
There's more…
Rebasing selective commits interactively
Getting ready
How to do it
There's more…
Squashing commits using an interactive rebase
Getting ready
How to do it...
There's more…
Changing the author of commits using a rebase
Getting ready
How to do it...
How it works...
Auto-squashing commits
Getting ready
How to do it...
There's more…
5. Storing Additional Information in Your Repository
Introduction
Adding your first Git note
Getting ready
How to do it…
There's more...
Separating notes by category
Getting ready
How to do it...
How it works...
Retrieving notes from the remote repository
Getting ready
How to do it...
How it works...
Pushing notes to a remote repository
How to do it...
There's more...
Tagging commits in the repository
Getting ready
How to do it...
There's more...
6. Extracting Data from the Repository
Introduction
Extracting the top contributor
Getting ready
How to do it...
There's more...
Finding bottlenecks in the source tree
Getting ready
How to do it...
There's more...
Grepping the commit messages
Getting ready
How to do it...
The contents of the releases
How to do it...
How it works...
7. Enhancing Your Daily Work with Git Hooks, Aliases, and Scripts
Introduction
Using a branch description in the commit message
Getting ready
How to do it...
Creating a dynamic commit message template
Getting ready
How to do it...
There's more...
Using external information in the commit message
Getting ready
How to do it...
Preventing the push of specific commits
Getting ready
How to do it...
There's more...
Configuring and using Git aliases
How to do it...
How it works...
Configuring and using Git scripts
How to do it...
Setting up and using a commit template
Getting ready
How to do it...
8. Recovering from Mistakes
Introduction
Undo – remove a commit completely
Getting ready
How to do it...
How it works…
Undo – remove a commit and retain the changes to files
Getting ready
How to do it...
How it works…
Undo – remove a commit and retain the changes in the staging area
Getting ready
How to do it...
How it works…
Undo – working with a dirty area
Getting ready
How to do it...
How it works…
See also
Redo – recreate the latest commit with new changes
Getting ready
How to do it...
How it works...
There is more…
Revert – undo the changes introduced by a commit
Getting ready
How to do it...
How it works...
There's more...
Reverting a merge
Getting ready
How to do it...
How it works...
There is more...
See also
Viewing past Git actions with git reflog
Getting ready
How to do it...
How it works...
Finding lost changes with git fsck
Getting ready
How to do it...
How it works...
See also
9. Repository Maintenance
Introduction
Pruning remote branches
Getting ready
How to do it...
How it works…
There's more…
Running garbage collection manually
Getting ready
How to do it...
How it works…
Turning off automatic garbage collection
Getting ready
How to do it...
Splitting a repository
Getting ready
How to do it...
How it works…
There's more…
Rewriting history – changing a single file
Getting ready
How to do it...
How it works…
Back up your repositories as mirror repositories
Getting ready
How to do it...
How it works…
There's more…
A quick submodule how-to
Getting ready
How to do it...
There's more…
Subtree merging
Getting ready
How to do it...
How it works…
See also
Submodule versus subtree merging
10. Patching and Offline Sharing
Introduction
Creating patches
Getting ready
How to do it...
How it works…
There's more…
Creating patches from branches
Getting ready
How to do it...
How it works…
There's more…
Applying patches
Getting ready
How to do it...
How it works…
There's more…
Sending patches
Getting ready
How to do it...
How it works…
There's more…
Creating Git bundles
Getting ready
How to do it...
How it works…
Using a Git bundle
Getting ready
How to do it…
There's more…
Creating archives from a tree
Getting ready
How to do it...
There's more…
11. Git Plumbing and Attributes
Introduction
Displaying the repository information
Getting ready
How to do it...
There's more…
Displaying the tree information
Getting ready
How to do it...
Displaying the file information
Getting ready
How to do it...
There's more…
Writing a blob object to the database
Getting ready
How to do it...
How it works…
There's more…
Writing a tree object to the database
Getting ready
How to do it...
How it works…
Writing a commit object to the database
Getting ready
How to do it...
How it works…
Keyword expansion with attribute filters
Getting ready
How to do it...
How it works…
There's more…
Metadata diff of binary files
Getting ready
How to do it...
How it works…
There's more…
Storing binaries elsewhere
Getting ready
How to do it...
How it works…
There's more…
See also
Checking the attributes of a file
Getting ready
How to do it...
Attributes to export an archive
Getting ready
How to do it...
There's more…
12. Tips and Tricks
Introduction
Using git stash
Getting ready
How to do it...
How it works…
There's more…
Saving and applying stashes
Getting ready
How to do it...
There's more…
Debugging with git bisect
Getting ready
How to do it...
There's more…
Using the blame command
Getting ready
How to do it...
There's more…
Color UI in the prompt
Getting ready
How to do it...
There's more…
Autocompletion
Getting ready
Linux
Mac
Windows
How to do it...
How it works…
There's more…
Bash prompt with status information
Getting ready
How to do it...
How it works…
There's more…
See also
More aliases
Getting ready
How to do it...
Interactive add
Getting ready
How to do it...
There's more…
Interactive add with Git GUI
Getting ready
How to do it...
Ignoring files
Getting ready
How to do it...
There's more…
See also…
Showing and cleaning ignored files
Getting ready
How to do it...
There's more…
III. Module 3
1. Git Basics in Practice
An introduction to version control and Git
Git by example
Repository setup
Creating a Git repository
Cloning the repository and creating the first commit
Publishing changes
Examining history and viewing changes
Renaming and moving files
Updating your repository (with merge)
Creating a tag
Resolving a merge conflict
Adding files in bulk and removing files
Undoing changes to a file
Creating a new branch
Merging a branch (no conflicts)
Undoing an unpublished merge
Summary
2. Exploring Project History
Directed Acyclic Graphs
Whole-tree commits
Branches and tags
Branch points
Merge commits
Single revision selection
HEAD – the implicit revision
Branch and tag references
SHA-1 and the shortened SHA-1 identifier
Ancestry references
Reverse ancestry references: the git describe output
Reflog shortnames
Upstream of remote-tracking branches
Selecting revision by the commit message
Selecting the revision range
Single revision as a revision range
Double dot notation
Multiple points – including and excluding revisions
The revision range for a single revision
Triple-dot notation
Searching history
Limiting the number of revisions
Matching revision metadata
Time-limiting options
Matching commit contents
Commit parents
Searching changes in revisions
Selecting types of change
History of a file
Path limiting
History simplification
Blame – the line-wise history of a file
Finding bugs with git bisect
Selecting and formatting the git log output
Predefined and user defined output formats
Including, formatting, and summing up changes
Summarizing contributions
Viewing a revision and a file at revision
Summary
3. Developing with Git
Creating a new commit
The DAG view of creating a new commit
The index – a staging area for commits
Examining the changes to be committed
The status of the working directory
Examining differences from the last revision
Unified Git diff format
Selective commit
Selecting files to commit
Interactively selecting changes
Creating a commit step by step
Amending a commit
Working with branches
Creating a new branch
Creating orphan branches
Selecting and switching to a branch
Obstacles to switching to a branch
Anonymous branches
Git checkout DWIM-mery
Listing branches
Rewinding or resetting a branch
Deleting a branch
Changing the branch name
Summary
4. Managing Your Worktree
Ignoring files
Marking files as intentionally untracked
Which types of file should be ignored?
Listing ignored files
Ignoring changes in tracked files
File attributes
Identifying binary files and end-of-line conversions
Diff and merge configuration
Generating diffs and binary files
Configuring diff output
Performing a 3-way merge
Transforming files (content filtering)
Obligatory file transformations
Keyword expansion and substitution
Other built-in attributes
Defining attribute macros
Fixing mistakes with the reset command
Rewinding the branch head, softly
Removing or amending a commit
Squashing commits with reset
Resetting the branch head and the index
Splitting a commit with reset
Saving and restoring state with the WIP commit
Discarding changes and rewinding branch
Moving commits to a feature branch
Undoing a merge or a pull
Safer reset – keeping your changes
Rebase changes to an earlier revision
Stashing away your changes
Using git stash
Stash and the staging area
Stash internals
Un-applying a stash
Recovering stashes that were dropped erroneously
Managing worktrees and the staging area
Examining files and directories
Searching file contents
Un-tracking, un-staging, and un-modifying files
Resetting a file to the old version
Cleaning the working area
Multiple working directories
Summary
5. Collaborative Development with Git
Collaborative workflows
Bare repositories
Interacting with other repositories
The centralized workflow
The peer-to-peer or forking workflow
The maintainer or integration manager workflow
The hierarchical or dictator and lieutenants workflows
Managing remote repositories
The origin remote
Listing and examining remotes
Adding a new remote
Updating information about remotes
Renaming remotes
Changing the remote URLs
Changing the list of branches tracked by remote
Setting the default branch of remote
Deleting remote-tracking branches
Support for triangular workflows
Transport protocols
Local transport
Smart transports
Native Git protocol
SSH protocol
Smart HTTP(S) protocol
Offline transport with bundles
Cloning and updating with bundle
Using bundle to update an existing repository
Utilizing bundle to help with the initial clone
Remote transport helpers
Transport relay with remote helpers
Using foreign SCM repositories as remotes
Credentials/password management
Asking for passwords
Public key authentication for SSH
Credential helpers
Publishing your changes upstream
Pushing to a public repository
Generating a pull request
Exchanging patches
Chain of trust
Content-addressed storage
Lightweight, annotated, and signed tags
Lightweight tags
Annotated tags
Signed tags
Publishing tags
Tag verification
Signed commits
Merging signed tags (merge tags)
Summary
6. Advanced Branching Techniques
Types and purposes of branches
Long-running, perpetual branches
Integration, graduation, or progressive-stability branches
Per-release branches and per-release maintenance
Hotfix branches for security fixes
Per-customer or per-deployment branches
Automation branches
Mob branches for anonymous push access
The orphan branch trick
Short-lived branches
Topic or feature branches
Bugfix branches
Detached HEAD – the anonymous branch
Branching workflows and release engineering
The release and trunk branches workflow
The graduation, or progressive-stability branches workflow
The topic branches workflow
Graduation branches in a topic branch workflow
Branch management for a release in a topic branch workflow
Git-flow – a successful Git branching model
Fixing a security issue
Interacting with branches in remote repositories
Upstream and downstream
Remote-tracking branches and refspec
Remote-tracking branches
Refspec – remote to local branch mapping specification
Fetching and pulling versus pushing
Pull – fetch and update current branch
Pushing to the current branch in a nonbare remote repository
The default fetch refspec and push modes
Fetching and pushing branches and tags
Fetching branches
Fetching tags and automatic tag following
Pushing branches and tags
Push modes and their use
The simple push mode – the default
The matching push mode for maintainers
The upstream push mode for the centralized workflow
The current push mode for the blessed repository workflow
Summary
7. Merging Changes Together
Methods of combining changes
Merging branches
No divergence – fast-forward and up-to-date cases
Creating a merge commit
Merge strategies and their options
Reminder – merge drivers
Reminder – signing merges and merging tags
Copying and applying a changeset
Cherry-pick – creating a copy of a changeset
Revert – undoing an effect of a commit
Applying a series of commits from patches
Cherry-picking and reverting a merge
Rebasing a branch
Merge versus rebase
Types of rebase
Advanced rebasing techniques
Resolving merge conflicts
The three-way merge
Examining failed merges
Conflict markers in the worktree
Three stages in the index
Examining differences – the combined diff format
How do we get there: git log --merge
Avoiding merge conflicts
Useful merge options
Rerere – reuse recorded resolutions
Dealing with merge conflicts
Aborting a merge
Selecting ours or theirs version
Scriptable fixes – manual file remerging
Using graphical merge tools
Marking files as resolved and finalizing merges
Resolving rebase conflicts
git-imerge – incremental merge and rebase for git
Summary
8. Keeping History Clean
An introduction to Git internals
Git objects
The plumbing and porcelain Git commands
Environment variables used by Git
Environment variables affecting global behavior
Environment variables affecting repository locations
Environment variables affecting committing
Rewriting history
Amending the last commit
An interactive rebase
Reordering, removing, and fixing commits
Squashing commits
Splitting commits
Testing each rebased commit
External tools – patch management interfaces
Scripted rewrite with the git filter-branch
Running the filter-branch without filters
Available filter types for filter-branch and their use
Examples of using the git filter-branch
External tools for large-scale history rewriting
Removing files from the history with BFG Repo Cleaner
Editing the repository history with reposurgeon
The perils of rewriting published history
The consequences of upstream rewrite
Recovering from an upstream history rewrite
Amending history without rewriting
Reverting a commit
Reverting a faulty merge
Recovering from reverted merges
Storing additional information with notes
Adding notes to a commit
How notes are stored
Other categories and uses of notes
Rewriting history and notes
Publishing and retrieving notes
Using the replacements mechanism
The replacements mechanism
Example – joining histories with git replace
Historical note – grafts
Publishing and retrieving replacements
Summary
9. Managing Subprojects – Building a Living Framework
Managing library and framework dependencies
Managing dependencies outside Git
Manually importing the code into your project
A Git subtree for embedding the subproject code
Creating a remote for a subproject
Adding a subproject as a subtree
Cloning and updating superprojects with subtrees
Getting updates from subprojects with a subtree merge
Showing changes between a subtree and its upstream
Sending changes to the upstream of a subtree
The Git submodules solution: repository inside repository
Gitlinks, .git files, and the git submodule command
Adding a subproject as a submodule
Cloning superprojects with submodules
Updating submodules after superproject changes
Examining changes in a submodule
Getting updates from the upstream of the submodule
Sending submodule changes upstream
Transforming a subfolder into a subtree or submodule
Subtrees versus submodules
Use cases for subtrees
Use cases for submodules
Third-party subproject management solutions
Managing large Git repositories
Handling repositories with a very long history
Using shallow clones to get truncated history
Cloning only a single branch
Handling repositories with large binary files
Splitting the binary asset folder into a separate submodule
Storing large binary files outside the repository
Summary
10. Customizing and Extending Git
Git on the command line
Git-aware command prompt
Command-line completion for Git
Autocorrection for Git commands
Making the command line prettier
Alternative command line
Graphical interfaces
Types of graphical tools
Graphical diff and merge tools
Graphical interface examples
Configuring Git
Command-line options and environment variables
Git configuration files
The syntax of Git configuration files
Accessing the Git configuration
Basic client-side configuration
The rebase and merge setup, configuring pull
Preserving undo information – the expiry of objects
Formatting and whitespace
Server-side configuration
Per-file configuration with gitattributes
Automating Git with hooks
Installing a Git hook
A template for repositories
Client-side hooks
Commit process hooks
Hooks for applying patches from e-mails
Other client-side hooks
Server-side hooks
Extending Git
Command aliases for Git
Adding new Git commands
Credential helpers and remote helpers
Summary
11. Git Administration
Repository maintenance
Data recovery and troubleshooting
Recovering a lost commit
Troubleshooting Git
Git on the server
Server-side hooks
The pre-receive hook
Push-to-update hook for pushing to nonbare repositories
The update hook
The post-receive hook
The post-update hook (legacy mechanism)
Using hooks to implement the Git-enforced policy
Enforcing the policy with server-side hooks
Early notices about policy violations with client-side hooks
Signed pushes
Serving Git repositories
Local protocol
SSH protocol
Anonymous Git protocol
Smart HTTP(S) protocol
Dumb protocols
Remote helpers
Tools to manage Git repositories
Tips and tricks for hosting repositories
Reducing the size taken by repositories
Speeding up smart protocols with pack bitmaps
Solving the large nonresumable initial clone problem
Augmenting development workflows
Summary
12. Git Best Practices
Starting a project
Dividing work into repositories
Selecting the collaboration workflow
Choosing which files to keep under version control
Working on a project
Working on a topic branch
Deciding what to base your work on
Splitting changes into logically separate steps
Writing a good commit message
Preparing changes for submission
Integrating changes
Submitting and describing changes
The art of the change review
Responding to reviews and comments
Other recommendations
Don't panic, recovery is almost always possible
Don't change the published history
Numbering and tagging releases
Automate what is possible
Summary
A. Bibliography
Index
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Prev
Previous Chapter
Cover
Next
Next Chapter
Git: Mastering Version Control
Table of Contents
Git: Mastering Version Control
Git: Mastering Version Control
Credits
Preface
What this learning path covers
What you need for this learning path
Who this learning path is for
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
I. Module 1
1. Getting Started with Git
Installing Git
Running our first Git command
Setting up a new repository
Adding a file
Commit the added file
Modify a committed file
Summary
2. Git Fundamentals – Working Locally
Repository structure and file status life cycle
The working directory
File statuses
The staging area
Unstaging a file
The time metaphor
The past
The present
The future
Working with repositories
Unstaging a file
Viewing the history
Anatomy of a commit
The commit snapshot
The commit hash
Author, e-mail, and date
Commit messages
Committing a bunch of files
Ignoring some files and folders by default
Highlighting an important commit – Git tags
Taking another way – Git branching
Anatomy of branches
Looking at the current branches
Creating a new branch
Switching from branch to branch
Understanding what happens under the hood
A bird's eye view to branches
Typing is boring – Git aliases
Merging branches
Merge is not the end of the branch
Exercises
Exercise 2.1
What you will learn
Scenario
Results
Exercise 2.2
What you will learn
Scenario
Results
Deal with branches' modifications
Diffing branches
Using a visual diff tool
Resolving merge conflicts
Edit collisions
Resolving a removed file conflict
Keeping the edited file
Resolving conflicts by removing the file
Stashing
Summary
3. Git Fundamentals – Working Remotely
Working with remotes
Setting up a new GitHub account
Cloning a repository
Uploading modifications to remotes
What do I send to the remote when I push?
Pushing a new branch to the remote
The origin
Tracking branches
Downloading remote changes
Checking for modifications and downloading them
Applying downloaded changes
Going backward: publish a local repository to GitHub
Adding a remote to a local repository
Pushing a local branch to a remote repository
Social coding – collaborate using GitHub
Forking a repository
Submitting pull requests
Creating a pull request
Summary
4. Git Fundamentals – Niche Concepts, Configurations, and Commands
Dissecting the Git configuration
Configuration architecture
Configuration levels
System level
Global level
Repository level
Listing configurations
Editing configuration files manually
Setting up other environment configurations
Basic configurations
Typos autocorrection
Push default
Defining the default editor
Other configurations
Git aliases
Shortcuts to common commands
Creating commands
git unstage
git undo
git last
git difflast
Advanced aliases with external commands
Removing an alias
Aliasing the git command itself
Git references
Symbolic references
Ancestry references
The first parent
The second parent
World-wide techniques
Changing the last commit message
Tracing changes in a file
Cherry picking
Tricks
Bare repositories
Converting a regular repository to a bare one
Backup repositories
Archiving the repository
Bundling the repository
Summary
5. Obtaining the Most – Good Commits and Workflows
The art of committing
Building the right commit
Make only one change per commit
Split up features and tasks
Write commit messages before starting to code
Include the whole change in one commit
Describe the change, not what you have done
Don't be afraid to commit
Isolate meaningless commits
The perfect commit message
Writing a meaningful subject
Adding bulleted details lines, when needed
Tie other useful information
Special messages for releases
Conclusions
Adopting a workflow – a wise act
Centralized workflows
How they work
Feature branch workflow
GitFlow
The master branch
Hotfixes branches
The develop branch
The release branch
The feature branches
Conclusion
The GitHub flow
Anything in the master branch is deployable
Creating descriptive branches off of the master
Pushing to named branches constantly
Opening a pull request at any time
Merging only after a pull request review
Deploying immediately after review
Conclusions
Other workflows
The Linux kernel workflow
Summary
6. Migrating to Git
Before starting
Prerequisites
Working on a Subversion repository using Git
Creating a local Subversion repository
Checking out the Subversion repository with svn client
Cloning a Subversion repository from Git
Setting up a local Subversion server
Adding a tag and a branch
Committing a file to Subversion using Git as a client
Using Git with a Subversion repository
Migrating a Subversion repository
Retrieving the list of Subversion users
Cloning the Subversion repository
Preserving the ignored file list
Pushing to a local bare Git repository
Arranging branches and tags
Renaming the trunk branch to master
Converting Subversion tags to Git tags
Pushing the local repository to a remote
Comparing Git and Subversion commands
Summary
7. Git Resources
Git GUI clients
Windows
Git GUI
TortoiseGit
GitHub for Windows
Atlassian SourceTree
Cmder
Mac OS X
Linux
Building up a personal Git server with web interface
The SCM Manager
Learning Git in a visual manner
Git on the Internet
Git community on Google+
GitMinutes and Thomas Ferris Nicolaisen's blog
Ferdinando Santacroce's blog
Summary
II. Module 2
1. Navigating Git
Introduction
Git's objects
Getting ready
How to do it...
The commit object
The tree object
The blob object
The branch
The tag object
How it works...
There's more...
See also
The three stages
Getting ready
How to do it…
How it works…
See also
Viewing the DAG
Getting ready
How to do it...
How it works...
See also
Extracting fixed issues
Getting ready
How to do it...
How it works...
There's more...
Getting a list of the changed files
Getting ready
How to do it...
How it works...
There's more...
See also
Viewing history with Gitk
Getting ready
How to do it...
How it works...
There's more...
Finding commits in history
Getting ready
How to do it...
How it works...
There's more...
Searching through history code
Getting ready
How to do it...
How it works...
There's more...
2. Configuration
Configuration targets
Getting ready
How to do it...
How it works...
There's more...
Querying the existing configuration
Getting ready
How to do it...
How it works...
There's more...
Templates
Getting ready
How to do it...
How it works...
A .git directory template
Getting ready
How to do it...
How it works...
See also
A few configuration examples
Getting ready
How to do it...
Rebase and merge setup
Expiry of objects
Autocorrect
How it works...
There's more...
Git aliases
Getting ready
How to do it...
How it works...
There's more...
The refspec exemplified
Getting ready
How to do it...
How it works...
3. Branching, Merging, and Options
Introduction
Managing your local branches
Getting ready
How to do it…
How it works…
There's more...
Branches with remotes
Getting ready
How to do it…
There's more...
Forcing a merge commit
Getting ready
How to do it...
There's more…
Using git rerere to merge known conflicts
How to do it…
There's more...
The difference between branches
Getting ready
How to do it…
There's more…
4. Rebase Regularly and Interactively, and Other Use Cases
Introduction
Rebasing commits to another branch
Getting ready
How to do it…
How it works
Continuing a rebase with merge conflicts
How to do it
How it works
There's more…
Rebasing selective commits interactively
Getting ready
How to do it
There's more…
Squashing commits using an interactive rebase
Getting ready
How to do it...
There's more…
Changing the author of commits using a rebase
Getting ready
How to do it...
How it works...
Auto-squashing commits
Getting ready
How to do it...
There's more…
5. Storing Additional Information in Your Repository
Introduction
Adding your first Git note
Getting ready
How to do it…
There's more...
Separating notes by category
Getting ready
How to do it...
How it works...
Retrieving notes from the remote repository
Getting ready
How to do it...
How it works...
Pushing notes to a remote repository
How to do it...
There's more...
Tagging commits in the repository
Getting ready
How to do it...
There's more...
6. Extracting Data from the Repository
Introduction
Extracting the top contributor
Getting ready
How to do it...
There's more...
Finding bottlenecks in the source tree
Getting ready
How to do it...
There's more...
Grepping the commit messages
Getting ready
How to do it...
The contents of the releases
How to do it...
How it works...
7. Enhancing Your Daily Work with Git Hooks, Aliases, and Scripts
Introduction
Using a branch description in the commit message
Getting ready
How to do it...
Creating a dynamic commit message template
Getting ready
How to do it...
There's more...
Using external information in the commit message
Getting ready
How to do it...
Preventing the push of specific commits
Getting ready
How to do it...
There's more...
Configuring and using Git aliases
How to do it...
How it works...
Configuring and using Git scripts
How to do it...
Setting up and using a commit template
Getting ready
How to do it...
8. Recovering from Mistakes
Introduction
Undo – remove a commit completely
Getting ready
How to do it...
How it works…
Undo – remove a commit and retain the changes to files
Getting ready
How to do it...
How it works…
Undo – remove a commit and retain the changes in the staging area
Getting ready
How to do it...
How it works…
Undo – working with a dirty area
Getting ready
How to do it...
How it works…
See also
Redo – recreate the latest commit with new changes
Getting ready
How to do it...
How it works...
There is more…
Revert – undo the changes introduced by a commit
Getting ready
How to do it...
How it works...
There's more...
Reverting a merge
Getting ready
How to do it...
How it works...
There is more...
See also
Viewing past Git actions with git reflog
Getting ready
How to do it...
How it works...
Finding lost changes with git fsck
Getting ready
How to do it...
How it works...
See also
9. Repository Maintenance
Introduction
Pruning remote branches
Getting ready
How to do it...
How it works…
There's more…
Running garbage collection manually
Getting ready
How to do it...
How it works…
Turning off automatic garbage collection
Getting ready
How to do it...
Splitting a repository
Getting ready
How to do it...
How it works…
There's more…
Rewriting history – changing a single file
Getting ready
How to do it...
How it works…
Back up your repositories as mirror repositories
Getting ready
How to do it...
How it works…
There's more…
A quick submodule how-to
Getting ready
How to do it...
There's more…
Subtree merging
Getting ready
How to do it...
How it works…
See also
Submodule versus subtree merging
10. Patching and Offline Sharing
Introduction
Creating patches
Getting ready
How to do it...
How it works…
There's more…
Creating patches from branches
Getting ready
How to do it...
How it works…
There's more…
Applying patches
Getting ready
How to do it...
How it works…
There's more…
Sending patches
Getting ready
How to do it...
How it works…
There's more…
Creating Git bundles
Getting ready
How to do it...
How it works…
Using a Git bundle
Getting ready
How to do it…
There's more…
Creating archives from a tree
Getting ready
How to do it...
There's more…
11. Git Plumbing and Attributes
Introduction
Displaying the repository information
Getting ready
How to do it...
There's more…
Displaying the tree information
Getting ready
How to do it...
Displaying the file information
Getting ready
How to do it...
There's more…
Writing a blob object to the database
Getting ready
How to do it...
How it works…
There's more…
Writing a tree object to the database
Getting ready
How to do it...
How it works…
Writing a commit object to the database
Getting ready
How to do it...
How it works…
Keyword expansion with attribute filters
Getting ready
How to do it...
How it works…
There's more…
Metadata diff of binary files
Getting ready
How to do it...
How it works…
There's more…
Storing binaries elsewhere
Getting ready
How to do it...
How it works…
There's more…
See also
Checking the attributes of a file
Getting ready
How to do it...
Attributes to export an archive
Getting ready
How to do it...
There's more…
12. Tips and Tricks
Introduction
Using git stash
Getting ready
How to do it...
How it works…
There's more…
Saving and applying stashes
Getting ready
How to do it...
There's more…
Debugging with git bisect
Getting ready
How to do it...
There's more…
Using the blame command
Getting ready
How to do it...
There's more…
Color UI in the prompt
Getting ready
How to do it...
There's more…
Autocompletion
Getting ready
Linux
Mac
Windows
How to do it...
How it works…
There's more…
Bash prompt with status information
Getting ready
How to do it...
How it works…
There's more…
See also
More aliases
Getting ready
How to do it...
Interactive add
Getting ready
How to do it...
There's more…
Interactive add with Git GUI
Getting ready
How to do it...
Ignoring files
Getting ready
How to do it...
There's more…
See also…
Showing and cleaning ignored files
Getting ready
How to do it...
There's more…
III. Module 3
1. Git Basics in Practice
An introduction to version control and Git
Git by example
Repository setup
Creating a Git repository
Cloning the repository and creating the first commit
Publishing changes
Examining history and viewing changes
Renaming and moving files
Updating your repository (with merge)
Creating a tag
Resolving a merge conflict
Adding files in bulk and removing files
Undoing changes to a file
Creating a new branch
Merging a branch (no conflicts)
Undoing an unpublished merge
Summary
2. Exploring Project History
Directed Acyclic Graphs
Whole-tree commits
Branches and tags
Branch points
Merge commits
Single revision selection
HEAD – the implicit revision
Branch and tag references
SHA-1 and the shortened SHA-1 identifier
Ancestry references
Reverse ancestry references: the git describe output
Reflog shortnames
Upstream of remote-tracking branches
Selecting revision by the commit message
Selecting the revision range
Single revision as a revision range
Double dot notation
Multiple points – including and excluding revisions
The revision range for a single revision
Triple-dot notation
Searching history
Limiting the number of revisions
Matching revision metadata
Time-limiting options
Matching commit contents
Commit parents
Searching changes in revisions
Selecting types of change
History of a file
Path limiting
History simplification
Blame – the line-wise history of a file
Finding bugs with git bisect
Selecting and formatting the git log output
Predefined and user defined output formats
Including, formatting, and summing up changes
Summarizing contributions
Viewing a revision and a file at revision
Summary
3. Developing with Git
Creating a new commit
The DAG view of creating a new commit
The index – a staging area for commits
Examining the changes to be committed
The status of the working directory
Examining differences from the last revision
Unified Git diff format
Selective commit
Selecting files to commit
Interactively selecting changes
Creating a commit step by step
Amending a commit
Working with branches
Creating a new branch
Creating orphan branches
Selecting and switching to a branch
Obstacles to switching to a branch
Anonymous branches
Git checkout DWIM-mery
Listing branches
Rewinding or resetting a branch
Deleting a branch
Changing the branch name
Summary
4. Managing Your Worktree
Ignoring files
Marking files as intentionally untracked
Which types of file should be ignored?
Listing ignored files
Ignoring changes in tracked files
File attributes
Identifying binary files and end-of-line conversions
Diff and merge configuration
Generating diffs and binary files
Configuring diff output
Performing a 3-way merge
Transforming files (content filtering)
Obligatory file transformations
Keyword expansion and substitution
Other built-in attributes
Defining attribute macros
Fixing mistakes with the reset command
Rewinding the branch head, softly
Removing or amending a commit
Squashing commits with reset
Resetting the branch head and the index
Splitting a commit with reset
Saving and restoring state with the WIP commit
Discarding changes and rewinding branch
Moving commits to a feature branch
Undoing a merge or a pull
Safer reset – keeping your changes
Rebase changes to an earlier revision
Stashing away your changes
Using git stash
Stash and the staging area
Stash internals
Un-applying a stash
Recovering stashes that were dropped erroneously
Managing worktrees and the staging area
Examining files and directories
Searching file contents
Un-tracking, un-staging, and un-modifying files
Resetting a file to the old version
Cleaning the working area
Multiple working directories
Summary
5. Collaborative Development with Git
Collaborative workflows
Bare repositories
Interacting with other repositories
The centralized workflow
The peer-to-peer or forking workflow
The maintainer or integration manager workflow
The hierarchical or dictator and lieutenants workflows
Managing remote repositories
The origin remote
Listing and examining remotes
Adding a new remote
Updating information about remotes
Renaming remotes
Changing the remote URLs
Changing the list of branches tracked by remote
Setting the default branch of remote
Deleting remote-tracking branches
Support for triangular workflows
Transport protocols
Local transport
Smart transports
Native Git protocol
SSH protocol
Smart HTTP(S) protocol
Offline transport with bundles
Cloning and updating with bundle
Using bundle to update an existing repository
Utilizing bundle to help with the initial clone
Remote transport helpers
Transport relay with remote helpers
Using foreign SCM repositories as remotes
Credentials/password management
Asking for passwords
Public key authentication for SSH
Credential helpers
Publishing your changes upstream
Pushing to a public repository
Generating a pull request
Exchanging patches
Chain of trust
Content-addressed storage
Lightweight, annotated, and signed tags
Lightweight tags
Annotated tags
Signed tags
Publishing tags
Tag verification
Signed commits
Merging signed tags (merge tags)
Summary
6. Advanced Branching Techniques
Types and purposes of branches
Long-running, perpetual branches
Integration, graduation, or progressive-stability branches
Per-release branches and per-release maintenance
Hotfix branches for security fixes
Per-customer or per-deployment branches
Automation branches
Mob branches for anonymous push access
The orphan branch trick
Short-lived branches
Topic or feature branches
Bugfix branches
Detached HEAD – the anonymous branch
Branching workflows and release engineering
The release and trunk branches workflow
The graduation, or progressive-stability branches workflow
The topic branches workflow
Graduation branches in a topic branch workflow
Branch management for a release in a topic branch workflow
Git-flow – a successful Git branching model
Fixing a security issue
Interacting with branches in remote repositories
Upstream and downstream
Remote-tracking branches and refspec
Remote-tracking branches
Refspec – remote to local branch mapping specification
Fetching and pulling versus pushing
Pull – fetch and update current branch
Pushing to the current branch in a nonbare remote repository
The default fetch refspec and push modes
Fetching and pushing branches and tags
Fetching branches
Fetching tags and automatic tag following
Pushing branches and tags
Push modes and their use
The simple push mode – the default
The matching push mode for maintainers
The upstream push mode for the centralized workflow
The current push mode for the blessed repository workflow
Summary
7. Merging Changes Together
Methods of combining changes
Merging branches
No divergence – fast-forward and up-to-date cases
Creating a merge commit
Merge strategies and their options
Reminder – merge drivers
Reminder – signing merges and merging tags
Copying and applying a changeset
Cherry-pick – creating a copy of a changeset
Revert – undoing an effect of a commit
Applying a series of commits from patches
Cherry-picking and reverting a merge
Rebasing a branch
Merge versus rebase
Types of rebase
Advanced rebasing techniques
Resolving merge conflicts
The three-way merge
Examining failed merges
Conflict markers in the worktree
Three stages in the index
Examining differences – the combined diff format
How do we get there: git log --merge
Avoiding merge conflicts
Useful merge options
Rerere – reuse recorded resolutions
Dealing with merge conflicts
Aborting a merge
Selecting ours or theirs version
Scriptable fixes – manual file remerging
Using graphical merge tools
Marking files as resolved and finalizing merges
Resolving rebase conflicts
git-imerge – incremental merge and rebase for git
Summary
8. Keeping History Clean
An introduction to Git internals
Git objects
The plumbing and porcelain Git commands
Environment variables used by Git
Environment variables affecting global behavior
Environment variables affecting repository locations
Environment variables affecting committing
Rewriting history
Amending the last commit
An interactive rebase
Reordering, removing, and fixing commits
Squashing commits
Splitting commits
Testing each rebased commit
External tools – patch management interfaces
Scripted rewrite with the git filter-branch
Running the filter-branch without filters
Available filter types for filter-branch and their use
Examples of using the git filter-branch
External tools for large-scale history rewriting
Removing files from the history with BFG Repo Cleaner
Editing the repository history with reposurgeon
The perils of rewriting published history
The consequences of upstream rewrite
Recovering from an upstream history rewrite
Amending history without rewriting
Reverting a commit
Reverting a faulty merge
Recovering from reverted merges
Storing additional information with notes
Adding notes to a commit
How notes are stored
Other categories and uses of notes
Rewriting history and notes
Publishing and retrieving notes
Using the replacements mechanism
The replacements mechanism
Example – joining histories with git replace
Historical note – grafts
Publishing and retrieving replacements
Summary
9. Managing Subprojects – Building a Living Framework
Managing library and framework dependencies
Managing dependencies outside Git
Manually importing the code into your project
A Git subtree for embedding the subproject code
Creating a remote for a subproject
Adding a subproject as a subtree
Cloning and updating superprojects with subtrees
Getting updates from subprojects with a subtree merge
Showing changes between a subtree and its upstream
Sending changes to the upstream of a subtree
The Git submodules solution: repository inside repository
Gitlinks, .git files, and the git submodule command
Adding a subproject as a submodule
Cloning superprojects with submodules
Updating submodules after superproject changes
Examining changes in a submodule
Getting updates from the upstream of the submodule
Sending submodule changes upstream
Transforming a subfolder into a subtree or submodule
Subtrees versus submodules
Use cases for subtrees
Use cases for submodules
Third-party subproject management solutions
Managing large Git repositories
Handling repositories with a very long history
Using shallow clones to get truncated history
Cloning only a single branch
Handling repositories with large binary files
Splitting the binary asset folder into a separate submodule
Storing large binary files outside the repository
Summary
10. Customizing and Extending Git
Git on the command line
Git-aware command prompt
Command-line completion for Git
Autocorrection for Git commands
Making the command line prettier
Alternative command line
Graphical interfaces
Types of graphical tools
Graphical diff and merge tools
Graphical interface examples
Configuring Git
Command-line options and environment variables
Git configuration files
The syntax of Git configuration files
Accessing the Git configuration
Basic client-side configuration
The rebase and merge setup, configuring pull
Preserving undo information – the expiry of objects
Formatting and whitespace
Server-side configuration
Per-file configuration with gitattributes
Automating Git with hooks
Installing a Git hook
A template for repositories
Client-side hooks
Commit process hooks
Hooks for applying patches from e-mails
Other client-side hooks
Server-side hooks
Extending Git
Command aliases for Git
Adding new Git commands
Credential helpers and remote helpers
Summary
11. Git Administration
Repository maintenance
Data recovery and troubleshooting
Recovering a lost commit
Troubleshooting Git
Git on the server
Server-side hooks
The pre-receive hook
Push-to-update hook for pushing to nonbare repositories
The update hook
The post-receive hook
The post-update hook (legacy mechanism)
Using hooks to implement the Git-enforced policy
Enforcing the policy with server-side hooks
Early notices about policy violations with client-side hooks
Signed pushes
Serving Git repositories
Local protocol
SSH protocol
Anonymous Git protocol
Smart HTTP(S) protocol
Dumb protocols
Remote helpers
Tools to manage Git repositories
Tips and tricks for hosting repositories
Reducing the size taken by repositories
Speeding up smart protocols with pack bitmaps
Solving the large nonresumable initial clone problem
Augmenting development workflows
Summary
12. Git Best Practices
Starting a project
Dividing work into repositories
Selecting the collaboration workflow
Choosing which files to keep under version control
Working on a project
Working on a topic branch
Deciding what to base your work on
Splitting changes into logically separate steps
Writing a good commit message
Preparing changes for submission
Integrating changes
Submitting and describing changes
The art of the change review
Responding to reviews and comments
Other recommendations
Don't panic, recovery is almost always possible
Don't change the published history
Numbering and tagging releases
Automate what is possible
Summary
A. Bibliography
Index
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset