How to create a new branch and navigate existing branches

Description

Collection: Change Management and Version ControlChapter: Branching, Merging and Tagging in Git

Transcript

Creating a branch is pretty straightforward. We use the git checkout command and then we pass it the b parameter. This is shorthand for creating a branch and immediately checking it out so we're working within that branch.

The last part is the name of the branch. We're going to call this one input-feature. We've been working on a module called input and so we'll move our development over to this feature branch.

Now you can name your branch whatever you want and so it's good to stick to certain naming conventions as we work through this and I'll point out which ones we're using where. For feature branches, we're just going to end it with a dash feature. I'm going to hit enter and now it says "Switched to a new branch input-feature.

" We can take a look at what branches exist in our repository by doing git branch. We see that there are two items listed here. There's input-feature.

It's green indicating that this is the current branch that we're on and then master which again is the default branch that's created with our repository when our repository was created. This asterisk is just another way to see what branch we're on. Now, again, as we mentioned in a previous video, whatever branch that we're on currently is HEAD.

So now HEAD, whenever we use it in git commands, will point to the input-feature branch as long as we're on it. If we want to switch between branches, we can simply do git checkout, and then the name of the branch. I did git checkout master and it switched us to master.

I can do git branch in order to show that we're definitely on master. And if we wanted to switch back, we'd simply do git checkout input-feature. And now it says "Switched to branch input-feature.

" Our new branch has the same history as the master branch at this point. If we do git log --oneline, we'd see that we have the same history that we have in the master branch. Let's go ahead and make a couple of commits to our new branch.

I'm going to jump back to the module input that we copied over to our sites/all/modules/custom directory in some of the last videos, and then I'm going to open up the second step, just the 02 step. I'm going to go ahead and copy the entire code and I'm going to paste it in the input dot module file. Now, if you don't already have this open, it's the input module file inside of our input module.

In this series we uncover how to use powerful tools to speed up and stabilize the Drupal development process. We begin with a thorough walk-through of Git, the version control system. After we cover how to patch modules and upgrade Drupal from one minor version to another, we demonstrate how to use the Features module to version control components of Drupal that aren't typically available to version control. Finally, we wrap up with how to integrate Drush - a powerful command line tool for Drupal - into your workflow to speed up the process of doing everything we discussed earlier in the series.

Some of the key points we'll be covering include:

How to use the command line

How to work with the Features module to capture important database changes and make deployment easier.

How to use Git for version control

Best practices for working on a Drupal team

Who this collection is for

This video collection is mainly for developers who want to improve their deployment strategies and learn how to work on a shared Drupal code base with other developers. However, even if you are not a developer, our coverage of using Features and version control is extremely valuable for deploying Drupal sites and sharing reusable components between projects.

Prerequisites

Even if you are not a developer, you will be able to follow with most of this collection. When we talk about code we do not go into detail about the basic components of the code, so you may want to brush up on some coding basics in the "PHP Programming Basics" collection.

It looks like there might be an issue playing videos in this browser. We're working on better cross-brower experience, but in the meantime please try the latest Chrome or Firefox browsers. Or, you may be able to watch the video directly without progress tracking or transcript: