Git Branches

Git has been a very amazing tool for developers, it makes it easier to work as a team, to collaborate with other developers to keep track of our codes, to manage different versions of your applications. Git branches are a feature of git that helps us manage the different timelines we create using git, it's basically like a set of unique code changes with different names. It helps separate development work from the final product so, in a way, It's a way for us to fine-tune our final product. When more than one person is working on a project, the branches helps us manage all the changes they make to the project. One of the most important rule when working with git is "do not mess with the master branch", why ?, well like I said earlier git branches helps us fine-tune our final product and that final product is kept in our master branch. When we create a repository on git the master branch is created automatically, to ensure that every single line of code is working properly, every single feature is working fine we do not push directly to the master branch because it's our production branch. Take for instance we have built an app and deployed let's say on Heroku, then one day we get an idea for a new feature for our app and we decide to build it and test it on the app but to ensure we don't lose our code we want to push to git, remember our master branch is our production branch and most of the time our deployment branch. If we push to the master branch, automatically everyone using that app will get the update and if it's not yet working fine it means everyone using the app will also have a problem, so we use branches to avoid this. We create other branches to ensure that any code we push to our master branch has been tested and it's working very fine. To begin working with git branches, move to the terminal you use, and open your project folder. The first thing you should always check is the branch you're working on, to do this you type "git branch -a" this will list all the branches and there will be an asterisk beside the master branch, showing that you're currently on the master branch. Now that you're done with that it's time to create your branch, we also do that first step to see the names of all branches and to see which other branches your teammates are working on. To create your branch you type in the command "git checkout -b {branch name} " you should get a response like "switched to a new branch {branch name}", note that the curly braces won't be there when you're working, I just put it there to indicate that it's holding a variable. If a branch already exists with the name you used then you will get an error but no problem, all you have to do is run the command with a different name. Once you have done that you can start making changes on this branch, so our master branch remains clean and untainted. When you're sure that your code is working properly, you can commit your code to the branch and push it, when you go on GitHub you'll realize that the master branch doesn't know about all these changes. It will be free from any untested code you have written, when you're done and very sure your code is working we can now merge to the master branch. First, you have to switch to your master branch, to do that type " git checkout master" on your terminal and you have switched. To merge just type "git merge -no -ff" and it will merge the changes with your master branch then all you have to is git push and push all changes to your master branch, that way you have ensured that anyone that visits the repository or is using your app will have only the best experience and nothing less. If you're working in a team on the other hand, and you do not have administrative access to the repository you have to raise a pull request for your code to be merged. Remember "never push to your master branch".