Before reading this, I hope that you understand what you are trying to achieve with branching. It is explained in my guide: ‘What are ‘branches’?‘. If you’re new to branching, please make sure you’ve read that first.
Now, assuming you’re familiar with branching, I’m going to go ahead and show you how to do the following things with branches in GitKraken:
- Create a branch
- Checkout / Switch to a branch
- Push a new branch
- Merge a branch
- Delete a branch
This guide strictly describes these procedures when using GitKraken, so hopefully you have come to the right place, and your interface looks something like this:
Let’s begin.
Create a branch
Branches in Git are like branches in trees, they have to branch off of something, like another branch. Every new project starts with a default branch called ‘master‘. So we will make a branch called development, which will branch off of master.
- Simply right click on your local master branch and select ‘Create branch here‘.
- Type the name of your new branch when prompted to do so. I have named mine ‘development‘.
You will be instantly switched to your new branch.
Checkout / Switch to a branch
In some git clients, you must also switch to your new branch after creating it, this happens for you automatically in GitKraken. However, just so you know, you can switch branches whenever you like by double-clicking on them under your local branches section.
Double-clicking on a remote branch that does not exist locally will checkout (AKA switch to) that branch and you will find it in your local branch list from then on.
Push a new branch
Push is what you do to take changes on your local repository (on your computer) and push those changes to your remote repository (like Gitlab).
Remember, we have created a new branch, and even switched to it. But this branch still only exists on your local repository. Your team members can’t access it, and if you try to work from a different computer, neither can you!
You need to push this new branch to the remote repository.
- Assuming you are currently checked out to your new branch, simply hit the push button at the top of your GitKraken window. Ignore the prompt that appears and hit the submit button.
- If you are not currently checked out to the branch you intend to push, then you can just right-click on the local branch you intend to push, and select ‘push’. Ignore the prompt that appears and hit the submit button.
Note that this is identical to trying to push when you have committed your work. If you’ve followed my setup guide correctly, Getting Started with GitKraken for Windows, then this should have worked successfully without any errors
If you have used GitLab as your server, like I suggested in Getting Started, then for your own peace of mind, you can also confirm the existence of your new branch by logging in to your GitLab account, clicking on your project, and viewing your branches. I won’t tell you how to do this, because I bet you can figure it out. But here’s what mine looks like on GitLab:
Not a necessary step, but this way you know for sure that the branch you created is accessible from places outside of your own computer.
So, now that you have a new branch, you can do THIS magic:
Did that not seem magical? Let me explain.
Some files have been created on the development branch, committed and then pushed. In the above GIF, you can see what my project folder looks like when I switch branches. Only the development branch has the 3 extra text files, but when we switch to the master branch, we can see that those files do not exist on master.
Hopefully, the above GIF demonstrates how branches are copies of your project, but with slight differences. So, what if you LIKE the changes on development, and feel like you need these same changes on the master branch? Then, you need to merge your branches!
Merge a branch
This process will take differences from another branch, and apply them to whichever branch you are currently working on. To make this magic happen, simply drag one local branch into another branch, it should open a menu, from which you want to select ‘Merge branchX into branchY‘, like so:
‘:
Once you have successfully merged, you may need to commit and push these changes. As the merge will only have happened on your local repository, not on the remote repository.
That’s it. You’ve mastered merging. Grats.
Deleting a branch
This is easy in GitKraken, simply right-click on any branch, either in local or remote, a menu will appear, select ‘Delete branchX‘. Note that you can’t delete a branch that you’re currently checked out to, you must checkout to a different branch first.
That’s it…
That’s all there is to know about branching in GitKraken! This is also the final topic I intend to cover for now. At this stage, if you have followed and understood my GitKraken guides up to this point, great! Also, I’d happily develop some software or games or complex art with you.
Cheers,
Regan.