Git Essentials

Book description

Create, merge, and distribute code with Git, the most powerful and flexible versioning system available

In Detail

Since its inception, Git has attracted skilled developers due to its robust, powerful, and reliable features. Its incredibly fast branching ability transformed a piece of code from a niche tool for former Linux Kernel developers into a mainstream distributed versioning system. Like most powerful tools, Git can be hard to approach since it has a lot of commands, subcommands, and options that easily confuse newcomers. The main purpose of Git Essentials is to help you overcome this fear and become adept at all basic tasks in Git. This book starts with an introduction to version control systems, and after this you'll delve deeply into the essentials of Git. This serves as a primer for the topics to follow such as branching and merging, creating and managing a GitHub personal repository, and fork and pull requests. You will then learn the art of cherry-picking, taking only commits you like, followed by Git blame. Finally, you'll learn how to migrate from SVN using Git tools or TortoiseGit and migrate from other VCSs, concluding with a collection of resources, links, and appendices.

What You Will Learn

  • Create, branch, and merge a local repository
  • Transport your work to a remote repository working in a centralized manner
  • Organize your source code using feature branches
  • Organize the development flow
  • Get a meaningful changelog using clear commit messages
  • Collaborate with teammates without any impediments
  • Experiment with your code without affecting functional code files
  • Explore some tools used to migrate to Git from other versioning systems without losing your development history
  • Extend your knowledge of Git with some useful resources

Table of contents

  1. Git Essentials
    1. Table of Contents
    2. Git Essentials
    3. Credits
    4. Foreword
    5. Foreword
    6. Foreword
    7. About the Author
    8. About the Reviewers
      1. Support files, eBooks, discount offers, and more
        1. Why subscribe?
        2. Free access for Packt account holders
    10. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Errata
        2. Piracy
        3. Questions
    11. 1. Getting Started with Git
      1. Installing Git
      2. Running our first Git command
        1. Setting up a new repository
        2. Adding a file
        3. Commit the added file
        4. Modify a committed file
      3. Summary
    12. 2. Git Fundamentals – Working Locally
      1. Repository structure and file status life cycle
        1. The working directory
          1. File statuses
        2. The staging area
          1. Unstaging a file
        3. The time metaphor
          1. The past
          2. The present
          3. The future
      2. Working with repositories
        1. Unstaging a file
      3. Viewing the history
        1. Anatomy of a commit
          1. The commit snapshot
          2. The commit hash
          3. Author, e-mail, and date
          4. Commit messages
        2. Committing a bunch of files
          1. Ignoring some files and folders by default
        3. Highlighting an important commit – Git tags
      4. Taking another way – Git branching
        1. Anatomy of branches
          1. Looking at the current branches
          2. Creating a new branch
          3. Switching from branch to branch
          4. Understanding what happens under the hood
          5. A bird's eye view to branches
          6. Typing is boring – Git aliases
        2. Merging branches
          1. Merge is not the end of the branch
        3. Exercises
          1. Exercise 2.1
            1. What you will learn
            2. Scenario
            3. Results
          2. Exercise 2.2
            1. What you will learn
            2. Scenario
            3. Results
        4. Deal with branches' modifications
          1. Diffing branches
          2. Using a visual diff tool
        5. Resolving merge conflicts
          1. Edit collisions
          2. Resolving a removed file conflict
            1. Keeping the edited file
            2. Resolving conflicts by removing the file
      5. Stashing
      6. Summary
    13. 3. Git Fundamentals – Working Remotely
      1. Working with remotes
        1. Setting up a new GitHub account
        2. Cloning a repository
        3. Uploading modifications to remotes
          1. What do I send to the remote when I push?
          2. Pushing a new branch to the remote
        4. The origin
          1. Tracking branches
        5. Downloading remote changes
          1. Checking for modifications and downloading them
          2. Applying downloaded changes
        6. Going backward: publish a local repository to GitHub
          1. Adding a remote to a local repository
          2. Pushing a local branch to a remote repository
        7. Social coding – collaborate using GitHub
          1. Forking a repository
          2. Submitting pull requests
          3. Creating a pull request
      2. Summary
    14. 4. Git Fundamentals – Niche Concepts, Configurations, and Commands
      1. Dissecting the Git configuration
        1. Configuration architecture
          1. Configuration levels
            1. System level
            2. Global level
            3. Repository level
          2. Listing configurations
          3. Editing configuration files manually
          4. Setting up other environment configurations
            1. Basic configurations
              1. Typos autocorrection
              2. Push default
              3. Defining the default editor
              4. Other configurations
      2. Git aliases
        1. Shortcuts to common commands
        2. Creating commands
          1. git unstage
          2. git undo
          3. git last
          4. git difflast
        3. Advanced aliases with external commands
        4. Removing an alias
        5. Aliasing the git command itself
      3. Git references
        1. Symbolic references
        2. Ancestry references
          1. The first parent
          2. The second parent
      4. World-wide techniques
        1. Changing the last commit message
        2. Tracing changes in a file
        3. Cherry picking
      5. Tricks
        1. Bare repositories
          1. Converting a regular repository to a bare one
        2. Backup repositories
          1. Archiving the repository
          2. Bundling the repository
      6. Summary
    15. 5. Obtaining the Most – Good Commits and Workflows
      1. The art of committing
        1. Building the right commit
          1. Make only one change per commit
            1. Split up features and tasks
            2. Write commit messages before starting to code
          2. Include the whole change in one commit
          3. Describe the change, not what you have done
          4. Don't be afraid to commit
          5. Isolate meaningless commits
          6. The perfect commit message
            1. Writing a meaningful subject
            2. Adding bulleted details lines, when needed
            3. Tie other useful information
            4. Special messages for releases
            5. Conclusions
      2. Adopting a workflow – a wise act
        1. Centralized workflows
          1. How they work
        2. Feature branch workflow
        3. GitFlow
          1. The master branch
          2. Hotfixes branches
          3. The develop branch
          4. The release branch
          5. The feature branches
          6. Conclusion
        4. The GitHub flow
          1. Anything in the master branch is deployable
          2. Creating descriptive branches off of the master
          3. Pushing to named branches constantly
          4. Opening a pull request at any time
          5. Merging only after a pull request review
          6. Deploying immediately after review
          7. Conclusions
        5. Other workflows
          1. The Linux kernel workflow
      3. Summary
    16. 6. Migrating to Git
      1. Before starting
        1. Prerequisites
      2. Working on a Subversion repository using Git
        1. Creating a local Subversion repository
        2. Checking out the Subversion repository with svn client
        3. Cloning a Subversion repository from Git
          1. Setting up a local Subversion server
        4. Adding a tag and a branch
        5. Committing a file to Subversion using Git as a client
      3. Using Git with a Subversion repository
      4. Migrating a Subversion repository
        1. Retrieving the list of Subversion users
        2. Cloning the Subversion repository
        3. Preserving the ignored file list
        4. Pushing to a local bare Git repository
        5. Arranging branches and tags
          1. Renaming the trunk branch to master
          2. Converting Subversion tags to Git tags
        6. Pushing the local repository to a remote
      5. Comparing Git and Subversion commands
      6. Summary
    17. 7. Git Resources
      1. Git GUI clients
        1. Windows
          1. Git GUI
          2. TortoiseGit
          3. GitHub for Windows
          4. Atlassian SourceTree
          5. Cmder
        2. Mac OS X
        3. Linux
      2. Building up a personal Git server with web interface
        1. The SCM Manager
      3. Learning Git in a visual manner
      4. Git on the Internet
        1. Git community on Google+
        2. GitMinutes and Thomas Ferris Nicolaisen's blog
        3. Ferdinando Santacroce's blog
      5. Summary
    18. Index

Product information

  • Title: Git Essentials
  • Author(s): Ferdinando Santacroce
  • Release date: April 2015
  • Publisher(s): Packt Publishing
  • ISBN: 9781785287909