Git in Action #11

Push and Branch

After we commit our changes a snapshot of our files will be created locally. Then when we connect our local to remote we will able to push our files to remote so our files will be saved on remote platform of our choice.
At this stage we have a newly created empty repository in remote and committed files in local. To send them to remote we use push command:

git push origin master

Here origin is the name of remote repository see note and master is our default branch. What is a branch? A branch is a version of your code which is created from a commit, simply put, it means we create a copy of our files from specific state of our project (meaning a commit) and work on our project parallelly in two or more versions of our project. It is the root feature that makes collaborative work possible.
In a fresh project after git init we have only one version of our files which by default is called master. So by above command we asking git to push our master branch to origin which now is completely empty, thus in github we will have one branch which has same name as our local namely master.

If you are a solo developer and your project is small and simple you may never want to have more than one branch, but in case you want to experiment something and you think it may fail, it is a good practice to create a branch and work on the branch if it works then you can merge it to your master and if it didn't work then just delete the branch and you are sure you still have your original files.
Another use-case is having development branch and production branch, for example if your project is a website and it is already live, you can have a development branch and work on that and whenever all the tests and results were acceptable merge it to production branch and make them live with minimum bugs.

Next Section