Friday, 28 December 2018

GIT: Creating and Applying Patch Files in Git

In a previous article, I talked about how to use git-cherry-pick to pluck a commit out of a repository branch and apply it to another branch. It’s a very handy tool to grab just what you need without pulling in a bunch of changes you don’t need or, more importantly, don’t want. This time the situation is the same. We have a commit we want to pull out of a branch and apply to a different branch. But our solution will be different. Instead of using git-cherry-pick we will create a patch file containing the changes and...

GIT: Using git-cherry-pick

Recently I ran into a problem on a project where I was working on the wrong branch and committed changes. Those commits were supposed to go elsewhere and I now I need to get them into the correct branch! There are a few options to solve this: Merge the incorrect branch into the correct branch. But I don’t want to that because there are items in the incorrect branch that I don’t want. So, that’s out. Recreate those changes in my working branch and just go on with my day. But that’s a waste of my time and I’m adamantly against redoing work! Create...

GIT: The Pieces of Git

As far as the Git workflow is concerned, there are three pieces of Git that we should be aware of before moving forward with some slightly more complex (but totally doable!) explanation. They are: Repository Index Working Tree Let’s cover each one in a bit more detail. Repository A repository is a collection of commits, and a record of what the project’s working tree looked like at one time. You can access the history of commits via the Git log. There’s always a current starting point in a repository and that’s called the HEAD. A repository...

GIT: The Big Picture of Git

When starting out with Git, it’s much easier to understand how to use it if we also understand the basics of what Git is. By that I mean what Git is beyond the commands. Conceptually speaking. What is a Version Control System (VCS)? Git is a version control system. You’ll hear this referred to as a VCS sometimes. This is a general term to describe tools that track changes to files over a period of time. The reason we track the changes is so we can revert to previous versions, have a log of the work that was completed, as well as have an incremental...

GIT: Git Merge Therapy

Git merge conflicts are normal and okay. They are supposed to happen and, most likely, will happen regularly. They don’t happen because you did something wrong. They happen because Git is trying to protect you from losing your hard work. If you’re new to Git or haven’t done extensive work with it in a team environment then you probably haven’t had the experience of a lot of merge conflicts. In a future article I will share how you can resolve conflicts but right now, let’s talk about prevention. We can do some things to prevent conflicts;...

GIT: Using Git Hooks

Git hooks are similar to SVN hooks; you can execute a script at a point in the Git routine. Git hooks are both local and server-side. The local hooks pertain to local activities, like committing, merging, checking out, etc. The server-side hooks deal with receiving pushes from a local client. The scripts that Git hooks execute are stored in the .git/hooks directory of your project. In every repository there are a collection of sample hooks that you can rename and use as inspiration for your own. The scripts can be in any language...

GIT: The Slowest Git Commit in the World

In Git there’s the concept of “porcelain” commands and “plumbing” commands. This obvious allusion to the toilet and its two types of interfaces. The simple, yet functional, porcelain. You interface with it and get the job done. Behind the scenes is the plumbing. This does the dirty work of completing the job. In Git, we have the same thing. The porcelain commands are the commands that you’ll typically use from the command line. git commit, etc. The plumbing commands are the low level commands that make up the Git system. They are the...