Git for Programmers
eBook - ePub

Git for Programmers

Master Git for effective implementation of version control for your programming projects

Jesse Liberty

  1. 264 páginas
  2. English
  3. ePUB (apto para móviles)
  4. Disponible en iOS y Android
eBook - ePub

Git for Programmers

Master Git for effective implementation of version control for your programming projects

Jesse Liberty

Detalles del libro
Vista previa del libro
Índice
Citas

Información del libro

Learn to track, branch, merge, and manage code revisions for real-world development scenarios

Key Features

  • Master Git and maintain your projects better through version control
  • Get to grips with Git's typical workflows, advanced functions, and their implementations
  • Learn the key Git commands to better manage your repository

Book Description

Whether you're looking for a book to deepen your understanding of Git or a refresher, this book is the ultimate guide to Git.

Git for Programmers comprehensively equips you with actionable insights on advanced Git concepts in an engaging and straightforward way. As you progress through the chapters, you'll gain expertise (and confidence) on Git with lots of practical use cases.

After a quick refresher on git history and installation, you'll dive straight into the creation and cloning of your repository. You'll explore Git places, branching, and GUIs to get familiar with the fundamentals. Then you'll learn how to handle merge conflicts, rebase, amend, interactive rebase, and use the log, as well as explore important Git commands for managing your repository.

The troubleshooting part of this Git book will include detailed instructions on how to bisect, blame, and several other problem handling techniques that will complete your newly acquired Git arsenal.

By the end of this book, you'll be using Git with confidence. Saving, sharing, managing files as well as undoing mistakes and basically rewriting history will be a breeze.

What you will learn

  • Create remote and local repositories and learn how to clone them
  • Understand the difference between local and remote repositories
  • Use, manage, and merge branches back into the main branch
  • Utilize tools to manage merge conflicts
  • Manage commits on your local machine through interactive rebasing
  • Use the log to gain control over all the data in your repository
  • Use bisect, blame, and other tools to undo Git mistakes

Who this book is for

If you have basic understanding of Git and want to strengthen your command over advanced techniques and navigate different functions, this book is for you. Knowing the fundamentals of Git will help you get the most out of this book, but beginners willing to invest some extra effort will be able to follow along as well.

Preguntas frecuentes

¿Cómo cancelo mi suscripción?
Simplemente, dirígete a la sección ajustes de la cuenta y haz clic en «Cancelar suscripción». Así de sencillo. Después de cancelar tu suscripción, esta permanecerá activa el tiempo restante que hayas pagado. Obtén más información aquí.
¿Cómo descargo los libros?
Por el momento, todos nuestros libros ePub adaptables a dispositivos móviles se pueden descargar a través de la aplicación. La mayor parte de nuestros PDF también se puede descargar y ya estamos trabajando para que el resto también sea descargable. Obtén más información aquí.
¿En qué se diferencian los planes de precios?
Ambos planes te permiten acceder por completo a la biblioteca y a todas las funciones de Perlego. Las únicas diferencias son el precio y el período de suscripción: con el plan anual ahorrarás en torno a un 30 % en comparación con 12 meses de un plan mensual.
¿Qué es Perlego?
Somos un servicio de suscripción de libros de texto en línea que te permite acceder a toda una biblioteca en línea por menos de lo que cuesta un libro al mes. Con más de un millón de libros sobre más de 1000 categorías, ¡tenemos todo lo que necesitas! Obtén más información aquí.
¿Perlego ofrece la función de texto a voz?
Busca el símbolo de lectura en voz alta en tu próximo libro para ver si puedes escucharlo. La herramienta de lectura en voz alta lee el texto en voz alta por ti, resaltando el texto a medida que se lee. Puedes pausarla, acelerarla y ralentizarla. Obtén más información aquí.
¿Es Git for Programmers un PDF/ePUB en línea?
Sí, puedes acceder a Git for Programmers de Jesse Liberty en formato PDF o ePUB, así como a otros libros populares de Computer Science y Software Development. Tenemos más de un millón de libros disponibles en nuestro catálogo para que explores.

Información

Año
2021
ISBN
9781801076036
Edición
1

4

Merging, Pull Requests, and Handling Merge Conflicts

In this chapter, you will see how to merge branches, using different types of merges. You will also see how to handle merge conflicts and tools to make managing conflicts easier. You will learn about pull requests and the difference between a fast-forward merge and a "true" merge.
In this chapter, you will learn:
  • How to push a commit to the server
  • How to manage your commits with the command line, Visual Studio, and GitHub Desktop
  • How to merge into the main branch
  • What a pull request is
  • What merge conflicts are and how to resolve them
  • What a fast-forward merge is
  • What a true merge is
Let's start with an overview of merging.

Merging overview

If you are on a feature branch, and the feature is sufficiently complete and tested, you will want to merge your branch back into the main branch. Some organizations let you simply merge, others (most?) require that you create a Pull Request (PR). A PR says, essentially, "Please examine my code and if you think it is right, merge it into the main branch."
Having a second (or third) set of eyes on your code before merging can save a lot of headaches later on (see Chapter 12, Fixing Mistakes (Undo), on fixing mistakes).
Often, if you've been careful (see below) you will merge without a problem. From time to time, however, you will run into the dreaded merge conflict. You'll see below a couple ways to handle that conflict.

Book

You will remember from the previous chapter that we have a directory, C:\GitHub\VisualStudio\ProGitForProgrammers, that is the home of the Books application and that we've been editing in Visual Studio. Of course, we don't have to manage it in Visual Studio; we can use any of our tools. For example, I can open the terminal and change directories to the Books app:
Figure 4.1: Opening the terminal
Notice that it says I have one commit to push (as indicated by the up-pointing arrow followed by the 1). I must have forgotten to do so the last time I was working with this code. I don't want to just push it, however—who knows what's in there? There are a few ways to find out.

What's in that push?

From the command line, we can use the git show command:
Figure 4.2: Examining the push
There's a lot of information here. First, we see the author and the date. Then we see the message that was attached to this commit (Add properties). Next, Git does a diff (difference) between Book.cs and Book.cs naming the first one a and the second b. The one labeled a is Book.cs before this commit, the one labeled b is the new contents in this commit.
You may have noticed the line that says /dev/null. This indicates that a file is being compared against nothing, and thus everything is new.
The next line shows that /dev/null is being compared against file b (the new Book.cs file):
Figure 4.3: Comparing against dev/null
What follows are the changes. Deletions will be marked in red, modifications in green, and new code in yellow. (This display and these colors may depend on which shell you are using.) We see here that three using statements, a namespace, and the class Book were all added in this commit. Before we push it, let's see what we can learn in Visual Studio.

Visual Studio

Opening the same directory in Visual Studio and going to the Git view reveals, as we would expect, that we have one commit to push (outgoing):
Figure 4.4: Visual Studio showing one file to push
Before we push, let's see what's in that push. Clicking on 1 outgoing opens two windows. The Branches window shows us which branch we are on (Book):
Figure 4.5: Visual Studio showing contents of the local repository
The middle panel has the really cool info. It tells you the local (as opposed to origin) history of your branches:
Figure 4.6: Visual Studio showing commit history
We can see that main has five commits (reading newest to oldest) and that preceding the newest commit in main, we have an outgoing commit on the Book branch, whose message is Add properties. This is consistent with what we saw at the command line.
We can go further, and return to Solution Explorer. Because there is more to see in Program.cs (rather than Book.cs), right-click on Program.cs and choose Git and then History. ...

Índice

  1. Preface
  2. Introduction
  3. Creating Your Repository
  4. Branching, Places, and GUIs
  5. Merging, Pull Requests, and Handling Merge Conflicts
  6. Rebasing, Amend, and Cherry-Picking
  7. Interactive Rebasing
  8. Workflow, Notes, and Tags
  9. Aliases
  10. Using the Log
  11. Important Git Commands and Metadata
  12. Finding a Broken Commit: Bisect and Blame
  13. Fixing Mistakes
  14. Next Steps
  15. Other Books You May Enjoy
  16. Index
Estilos de citas para Git for Programmers

APA 6 Citation

Liberty, J. (2021). Git for Programmers (1st ed.). Packt Publishing. Retrieved from https://www.perlego.com/book/2708221/git-for-programmers-master-git-for-effective-implementation-of-version-control-for-your-programming-projects-pdf (Original work published 2021)

Chicago Citation

Liberty, Jesse. (2021) 2021. Git for Programmers. 1st ed. Packt Publishing. https://www.perlego.com/book/2708221/git-for-programmers-master-git-for-effective-implementation-of-version-control-for-your-programming-projects-pdf.

Harvard Citation

Liberty, J. (2021) Git for Programmers. 1st edn. Packt Publishing. Available at: https://www.perlego.com/book/2708221/git-for-programmers-master-git-for-effective-implementation-of-version-control-for-your-programming-projects-pdf (Accessed: 15 October 2022).

MLA 7 Citation

Liberty, Jesse. Git for Programmers. 1st ed. Packt Publishing, 2021. Web. 15 Oct. 2022.