Creating Branches

Source code

Here's the code for the files we'll be using. Don't worry if you don't have Ruby installed; there's no need to run them. Our real goal is to learn how to track changes to these files.

decoder.rb

KEY={}# Define a method that takes an array of numbers to decode.defdecode(numbers)text=""# Process each number in the array.numbers.eachdo|number|# Get the letter that corresponds to this number.letter=KEY[number]# Add it onto the string.text+=letterend# Return the decoded string.returntextend

try_decoder.rb

require'./decoder'putsdecode([1,3,5])putsdecode([1,18,3,1,4,5])

Git branches

You've been working with one branch ever since you started using Git, perhaps without realizing it.

When you run git init, Git creates a new branch for you, called master. We can try this now: git init

If you run git status, it will show at the top that you're "On branch master".

Now, branches act like alternate timelines for your file contents, but in reality, a branch is just a pointer to a particular commit. Don't worry if you don't understand that right now, we'll be circling back to that idea later.

Making commits to the master branch is widely considered to be a bad idea, though. Most developers treat the master branch as code that has been thoroughly tested and is always ready to deploy to customers. If you've just finished some code that isn't thoroughly tested and ready to share, it shouldn't be committed to the master branch.

So where do we commit new code? To a new branch! Let's create one now.