

The second line tells us that on our remote, named origin, there is a single branch, also called master. The asterisk next to “master” in the first line of the output indicates that we are currently on that branch. Its appearance may vary somewhat depending on your OS and terminal application, but the info is ultimately the same.
#Create new branch git code#
This returns output you see in the code example below. We know about the master, but who knows what our project collaborators may be up to, those mischievous monkeys? So we can view all existing branches by typing “git branch -a” into terminal, which tells git that we want to see ALL the branches in this project, even ones that are not in our local workspace. Prior to creating new branches, we want to check for any other existing branches. Please now open up your version on your computer and cd into the directory. Let’s continue working with the sample project created for our previous tutorial, good ol’ studious_octo_carnival. To begin working on anything new in a project, or to change existing things, you create a branch off the stable master branch. Master then is updated to contain all the new stuff. Instead, everyone uses branches created from master to experiment, make edits and additions and changes, before eventually rolling that branch back into the master once they have been approved and are known to work.

The entire reason GitHub works is that it is always safe to work from the master.
#Create new branch git software#
The master branch is meant to be stable, and it is the social contract of open source software to never, ever push anything to master that is not tested, or that breaks the build. It is your production code, ready to roll out into the world. Why is the master so important to not mess with? One word: the master branch is deployable. If you make changes to the master branch of a group project while other people are also working on it, your on-the-fly changes will ripple out to affect everyone else and very quickly there will be merge conflicts, weeping, rending of garments, and plagues of locusts. This is the official working version of your project, and the one you see when you visit the project repository at /yourname/projectname.ĭo not mess with the master. The main branch - the one where all changes eventually get merged back into, and is called master.

Each repository can have one or more branches.

A branch is essentially is a unique set of code changes with a unique name. The way git, and GitHub, manage this timeline - especially when more than one person is working in the project and making changes - is by using branches. Essentially creating a timeline of versions of a project as it progresses, so that you can roll back to an earlier version in the event disaster strikes. Or at least not disastrous.īy now you understand that git saves each version of your project as a snapshot of the code exactly as it was at the moment you committed it. Now it is time to start actually working with GitHub (and git) the way they are meant to be used: making changes in the project safely off to one side, and merging them back into the original project once they have proved to be correct.
#Create new branch git how to#
In our previous tutorials for the git version control software, we learned the essential basic commands for using git, as well as how to work with to establish a repository and push our project code to the website.
