To begin working on anything new in a project, or to change existing things, you create a branch off the stable master branch.
![git create branch off previous commit git create branch off previous commit](https://about.gitlab.com/images/blogimages/keeping-git-commit-history-clean/GitRebase.png)
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.
Git create branch off previous commit 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.
![git create branch off previous commit git create branch off previous commit](https://miro.medium.com/max/1400/1*3p4m_Akh_BlutOnWnbywkg.png)
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.
Git create branch off previous commit 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.