Book Image

Mastering Git

5 (1)
Book Image

Mastering Git

5 (1)

Overview of this book

Git is one of the most popular types of Source Code Management (SCM) and Distributed Version Control System (DVCS). Despite the powerful and versatile nature of the tool enveloping strong support for nonlinear development and the ability to handle large projects efficiently, it is a complex tool and often regarded as “user-unfriendly”. Getting to know the ideas and concepts behind the architecture of Git will help you make full use of its power and understand its behavior. Learning the best practices and recommended workflows should help you to avoid problems and ensure trouble-free development. The book scope is meticulously designed to help you gain deeper insights into Git's architecture, its underlying concepts, behavior, and best practices. Mastering Git starts with a quick implementation example of using Git for a collaborative development of a sample project to establish the foundation knowledge of Git operational tasks and concepts. Furthermore, as you progress through the book, the tutorials provide detailed descriptions of various areas of usage: from archaeology, through managing your own work, to working with other developers. This book also helps augment your understanding to examine and explore project history, create and manage your contributions, set up repositories and branches for collaboration in centralized and distributed version control, integrate work from other developers, customize and extend Git, and recover from repository errors. By exploring advanced Git practices, you will attain a deeper understanding of Git’s behavior, allowing you to customize and extend existing recipes and write your own.
Table of Contents (19 chapters)
Mastering Git
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Stashing away your changes


Often, when you've been working on a project, and things are in a messy state not suitable for a permanent conflict, you want to temporarily save the current state and go to work on something else. The answer to this problem is the git stash command.

Stashing takes the dirty state of your working area—that is, your modified tracked files in your worktree (though you can also stash untracked files with the --include-untracked option), and the state of the staging area, then saves this state, and resets both the working directory and the index to the last committed version (to match the HEAD commit), effectively running git reset --hard HEAD. You can then reapply the stashed changes at any time.

Stashes are saved on a stack: by default you apply the last stashed changes (stash@{0}), though you can list stashed changes (with git stash list), and explicitly select any of the stashes.

Using git stash

If you don't expect for the interruption to last long, you can simply...