- What is Git?
- What are ‘branches’?
- Getting Started
Git allows us to split our work in to ‘branches’. Each branch is actually nothing more than a separate copy of our project. We work on that copy, and when we have finished our work, there are tools that help us ‘merge‘ our work in to other branches.
Imagine writing a book with someone, you agree to work on separate chapters of that book (to save time?), and at some point, you need to bring your pages together. You merge your collection of pages, thus making a book. Well, software and art projects can work in much the same way. You have people working on separate branches of your project, and later on, you put all of your work together.
The above diagram demonstrates a somewhat clean workflow. The idea is that NOBODY works on the master or development branches. These two branches are strictly maintained so that there is always a working copy of the product while team members edit (and break) the product on their own branches.
The master branch only receives changes from development when development has proven to be in good working order and in a state that’s presentable to clients. This way, master is forever in a state that’s presentable to clients without any questionable features or horrendous bugs. Further to maintain this, development is the only branch that’s ever allowed to merge to master.
This is my personal preference for a Git work flow, but it changes depending on the situation, this works fine for small/medium scale projects. It will differ depending on who you’re working for/with and what you’re making with which technology exactly.
Why do I want branches?
Often in large, creative projects, we are working on stuff that could easily fail, collapse or explode. Branches allow us peace of mind and a sense of actual security.
If you are experimenting for the day, you create a branch from your development. Let’s say that experiment doesn’t work out, or actually destroys your project. No problem, you can just delete this branch you made, and switch to your previous branch where your project is perfectly in tact.
One more example, let’s say you are going to be working on something quite complex for a few days, in this time, you know that you have to tear apart some functional elements of your project, and that doing so could interrupt someone else’s work. By working on your own branch, you can make these changes without affecting your colleagues files (assuming that they, too, are working on their own branches). In short, branches are a good way to isolate your work, and there are plenty of reasons why isolating your work is a valuable skill to have.
What exactly can I do with my branch?
Essentially, your branch is just a copy of your project folder. So here are things that we might do with this copy / branch.
- Create a branch.
- Do work in your branch.
- Switch to a different branch.
- Merge your branch into a someone else’s branch, or one of your own.
- Delete a branch.
That is pretty much all you can do with a branch. Well, all that you need to know for now and for most of the time, anyway.
I’m not getting it, it sounds stupid and pointless and dumb.
It’s true, you don’t have to use branching, and for those learning Git, branching is considered one of those advanced topics. However it is good to learn if you give it a chance, especially if you plan to work with companies or small teams at some point, branching can save your hide.
I don’t understand, can you show me an example?
Sure can. I feel like this is easier to describe in Tortoise. Watch as I switch between two branches. One branch is called ‘master’, the other is called ‘development’. Observe how when I switch branches, the files found in this directory will change. I hope this is easy enough to understand, but when we are switching branches, we are saying which version of this folder to use. My development branch happens to have files that the master branch does not.
I only intend to teach people what they need to know in order to manage their day-to-day tasks, so I will keep it as simple as possible as I cover how branching works for Tortoise and Kraken (look at these later), but for those using CLI, I expect my guide on Git Commands (simplified) should suffice.
If you really want more information about branches in Git, I would suggest the following link: https://www.atlassian.com/git/tutorials/using-branches/git-checkout.
That’s enough of the blablablah for now. Let’s get started!