Command Line Git - Everything You Need To Know To Get Started
()
About this ebook
Have you ever lost hours of work because you accidentally deleted a file or forgot to save it?
Or maybe you wanted to go back to a previous version of a file but couldn't, because the history of changes was not saved?
These are the problems that version control systems solve.
They allow you to save the history of changes and go back to any previous version of a file. On top of that they allow you to share the history of changes with other people.
Git is the defacto standard for version control. It is used in almost every software project. If you are a software developer, you need to know Git.
The goal of this book is to get you up and running using Git from the command line as quickly as possible without overwhelming you with too much information.
To make the learning process more intuitive and engaging, I use mental models, analogies and metaphors to help you understand and remember the concepts.
Related to Command Line Git - Everything You Need To Know To Get Started
Related ebooks
Node.js: Novice to Ninja Rating: 0 out of 5 stars0 ratingsComputer Programming JavaScript, Python, HTML, SQL, CSS Rating: 0 out of 5 stars0 ratingsGit Essentials Rating: 4 out of 5 stars4/5Instant MinGW Starter Rating: 0 out of 5 stars0 ratingsVisual Studio Code: End-to-End Editing and Debugging Tools for Web Developers Rating: 0 out of 5 stars0 ratingsProgrammer's Motivation for Beginners: Real Learning Stories & Tips Rating: 5 out of 5 stars5/5Git: Mastering Version Control Rating: 0 out of 5 stars0 ratingsRy's Git Tutorial Rating: 0 out of 5 stars0 ratingsJava with TDD from the Beginning Rating: 0 out of 5 stars0 ratingsGit Best Practices Guide Rating: 0 out of 5 stars0 ratingsPersistence in PHP with Doctrine ORM Rating: 0 out of 5 stars0 ratingsMastering Postman: A Comprehensive Guide to Building End-to-End APIs with Testing, Integration and Automation Rating: 0 out of 5 stars0 ratingsWebAssembly Essentials Rating: 0 out of 5 stars0 ratingsYour First Week With Node.js Rating: 0 out of 5 stars0 ratingsProgramming the Network with Perl Rating: 0 out of 5 stars0 ratingsAjax Bible Rating: 3 out of 5 stars3/5ASP.NET Application Development Fundamentals Rating: 0 out of 5 stars0 ratingsRust In Practice Rating: 0 out of 5 stars0 ratingsPractical C++ Backend Programming: Crafting Databases, APIs, and Web Servers for High-Performance Backend Rating: 0 out of 5 stars0 ratingsUseful Python Rating: 0 out of 5 stars0 ratingsFlutter for Jobseekers: Learn Flutter and take your cross-platform app development skills to the next level (English Edition) Rating: 0 out of 5 stars0 ratingsMy First Mobile App for Students: A comprehensive guide to Android app development for beginners (English Edition) Rating: 0 out of 5 stars0 ratingsPYTHON FOR BEGINNERS: Unraveling the Power of Python for Novice Coders (2023 Guide) Rating: 0 out of 5 stars0 ratingsPractical C++ Backend Programming Rating: 0 out of 5 stars0 ratingsBuilding Web APIs with ASP.NET Core Rating: 0 out of 5 stars0 ratingsLearn Angular: Build a Todo App Rating: 0 out of 5 stars0 ratingsSchematron: A language for validating XML Rating: 0 out of 5 stars0 ratings
Software Development & Engineering For You
Hand Lettering on the iPad with Procreate: Ideas and Lessons for Modern and Vintage Lettering Rating: 4 out of 5 stars4/5Level Up! The Guide to Great Video Game Design Rating: 4 out of 5 stars4/5Grokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5Learn to Code. Get a Job. The Ultimate Guide to Learning and Getting Hired as a Developer. Rating: 5 out of 5 stars5/5How to Write Effective Emails at Work Rating: 4 out of 5 stars4/5PYTHON: Practical Python Programming For Beginners & Experts With Hands-on Project Rating: 5 out of 5 stars5/5OneNote: The Ultimate Guide on How to Use Microsoft OneNote for Getting Things Done Rating: 1 out of 5 stars1/5Salesforce Certification: Earn Salesforce certifications and increase online sales real and unique practice tests included Kindle Rating: 0 out of 5 stars0 ratingsiPhone Application Development For Dummies Rating: 4 out of 5 stars4/5iOS App Development For Dummies Rating: 0 out of 5 stars0 ratingsFlow: A Handbook for Change-Makers, Mavericks, Innovators and Leaders Rating: 0 out of 5 stars0 ratingsPython For Dummies Rating: 4 out of 5 stars4/5Android App Development For Dummies Rating: 0 out of 5 stars0 ratingsHow Do I Do That In InDesign? Rating: 5 out of 5 stars5/5Modern C++ for Absolute Beginners: A Friendly Introduction to C++ Programming Language and C++11 to C++20 Standards Rating: 0 out of 5 stars0 ratingsSQL For Dummies Rating: 0 out of 5 stars0 ratingsThe Inmates Are Running the Asylum (Review and Analysis of Cooper's Book) Rating: 4 out of 5 stars4/5Lua Game Development Cookbook Rating: 0 out of 5 stars0 ratingsTiny Python Projects: Learn coding and testing with puzzles and games Rating: 5 out of 5 stars5/5Beginning C++ Programming Rating: 3 out of 5 stars3/5DevOps For Dummies Rating: 4 out of 5 stars4/527 PROGRAM MANAGEMENT INTERVIEW TECHNIQUES - To Ace That Dream Job Offer ! Rating: 5 out of 5 stars5/5The Essential Persona Lifecycle: Your Guide to Building and Using Personas Rating: 4 out of 5 stars4/5How Do I Do That in Photoshop?: The Quickest Ways to Do the Things You Want to Do, Right Now! Rating: 4 out of 5 stars4/5INSTANT PLC Programming with RSLogix 5000 Rating: 4 out of 5 stars4/5Learning Python Rating: 5 out of 5 stars5/5Managing Humans: Biting and Humorous Tales of a Software Engineering Manager Rating: 4 out of 5 stars4/5
Reviews for Command Line Git - Everything You Need To Know To Get Started
0 ratings0 reviews
Book preview
Command Line Git - Everything You Need To Know To Get Started - Maksim Ivanov
Command Line Git - Everything you need to know to get started
Illustrated guide to Git with useful mental models and exercises.
Maksim Ivanov
© 2023 Maksim Ivanov
Table of Contents
Introduction
Why Learn Git?
Why Use the Command Line?
Prerequisites
What You’ll Learn
How Git Works - Building a Mental Model
What is Version Control?
What is Distributed Version Control?
How Does Git Work?
Git Workflow
Installing and Using Git on Windows
Installing Git Using the Official Installer
PowerShell Primer
Installing Git on Mac OS
Installing Git on Linux
Installing Git
Mac OS and Linux Command Line Primer
How to Open the Command Line
How to Use the Command Line
Configuring Git
Configuration Levels
Configuring Git Using Text Files
Complete List of Available Settings
Using the Config Command
Setting Configuration Options
Removing Configuration Settings
Viewing Configuration Settings
Exercises
Creating a Repository
Before You Start
How to Clone a Repository
How to Initialize a Repository in an Existing Folder
What is Inside the .git Folder
Exercises
Checking the Status of a Repository
How to Use the Status Command
Short Status
Exercises
Selecting Changes to Commit - Staging
How to Stage Changes
Staging Multiple Files
Viewing Staged Changes
Removing Files From the Staging Area
Staging Individual Changes
Exercises
Committing Changes
Merge Commits
How to Commit Changes
How to Overwrite the Last Commit
Exercises
Understanding .gitignore
How to Ignore Files
Glob Patterns
Generate a .gitignore File for Your Project
Exercises
Viewing the Commit History
How to View the Commit History
How to View the Commit History in One Line
How to View the Commit History in a Graph
Exercises
Switching Between Commits
What Does It Mean to Switch Between Commits?
How to Switch to a Particular Commit
How to Switch Relative to the Current Commit
How to Switch Back
Exercises
Understanding HEAD
When the HEAD is Detached
What Happens When You Commit in the Detached HEAD State
How to Find Dangling Commits
How to Reattach the Dangling Commit
How to Fix the Detached HEAD
Exercises
Restoring the Working Directory
Discarding the Untracked Files
Discarding the Tracked Files
Discarding the Staged Files
Exercises
Undoing Changes
Reverting the Commit
Resetting Changes
Exercises
Using branches
How Does Git Store Branches
Creating New Branches
Switching Branches
Listing Branches
Deleting Branches
Merging Branches
Exercises
Resolving Merge Conflicts
How Conflicts Happen
How to Avoid Conflicts
How to Resolve Conflicts
Exercises
Stashing changes
What is a Stash?
Put Aside Changes
View Stashes
Using Named Stashes
Preview Stash Contents
Apply Stashes
Drop stash
Exercises
Using Remotes
What is a Remote
Adding a Remote
Adding GitHub as a Remote Repository
Listing Remotes
Pushing to a Remote Repository
Pulling or Fetching from a Remote Repository
Renaming Remotes
Removing Remotes
Exercises
Afterword
Appendix
Answers to Exercises
Introduction
This book aims to get you up and running using Git from the command line as quickly as possible without overwhelming you with too much information.
To make the learning process more intuitive and engaging, I use mental models, analogies, and metaphors to help you understand and remember the concepts.
I also use diagrams and illustrations. They help you visualize complex ideas and serve as entertainment to keep you engaged.
At the end of each chapter, you will find exercises crafted to reinforce the concepts you have just learned. These exercises are hands-on tasks that allow you to apply the new knowledge. By practicing what you learn, you understand the topics better and solidify the information in your memory. It is important to do the exercises. They will help you learn Git faster.
Why Learn Git?
Have you ever lost hours of work because you accidentally deleted a file or forgot to save it? Or you wanted to go back to a previous version of a file but couldn’t, because the history of changes was not saved.
These are the problems that version control systems solve. They allow you to save the history of changes and go back to any previous version of a file. On top of that, they allow you to share the history of changes with other people.
Git has become the standard for version control. It is used in almost every software project. If you are a software developer, you’ll need to know Git. But it will also be useful for anyone who works with text files.
I worked with several startup founders who, among other things, knew how to use Git. It helped them understand the development process better and reduced friction when working with the development team.
For example, they could pull the latest changes from the repository and test them on their local machine. Or they could switch to a branch that was created for a particular feature and preview it there.
Overall, it gave them a greater understanding of what was going on with the project and helped them make better decisions.
Why Use the Command Line?
Git has many applications with graphical user interfaces (GUI). Some of them are very good. So why use the command line?
I believe using Git from the command line is the best way to learn it. It’s also the most flexible way to use it. You won’t be limited to a particular GUI application or an editor plugin. You will be able to use Git from a remote server, from a virtual machine, or a Docker container. So you’ll be a lot more powerful.
Another benefit is that you’ll learn the language
that Git uses and not the language
of a particular GUI application. Some GUI applications hide the complexity of Git. It works great until something goes wrong. By using Git from the command line, you’ll learn the terms and concepts that Git uses. This will help you communicate with other developers and get help if you need it.
Prerequisites
You don’t need to know anything about Git to read this book. You don’t need to know anything about the command line either.
I will explain everything from the beginning, including all the concepts and commands.
You need a computer with a terminal and a text editor.
On Windows, you can use PowerShell or Git Bash. On Mac and Linux, you can use the built-in terminal.
You can use any text editor you like: VS Code, Sublime Text, and even Notepad will work.
What You’ll Learn
You’ll learn how to set up Git on your computer, how to create a repository, how to commit changes, how to create and merge branches, how to resolve merge conflicts, and how to
How Git Works - Building a Mental Model
Git gets easier once you get the basic idea
that branches are homeomorphic endofunctors
mapping submanifolds of a Hilbert space.
— @tabqwerty
In this chapter, we’ll create an imaginary picture of how Git works, the so-called mental model.
Having the right mental model is crucial. Git is a complex tool with many features. commands and options, but if you imagine working with Git a certain way, you’ll skip a lot of confusion and frustration.
This imaginary picture of