Git tutorial 2 ( Git Branching )
Git doesn’t store only the new changes, but it stores a snapshot of the data on each commit. One commit object is created that contains a pointer to the snapshot of the content. If you have made 3 commits on the same branch, it looks something like below :
Let’s create one new branch “test”.
$ git branch test
Checkout to branch “test” :
$ git checkout test
Now we have two branches “master” ,”test” and we have different commits on both of these branches.
In our last step, we will checkout back to the “master” branch, merge all changes from “test” branch to the master and finally delete this “test” branch.
//checkout back to master branch $ git checkout master //Merge changes in master: $ git checkout master $ git merge test //Delete test branch: $ git branch -d hotfix
Some useful Commands :
//Check branch and branch pointers $ git log --oneline --decorate //To check history of commits from different branches $ git log --oneline --decorate --graph --all //To create a branch and switch to it at the same time $ git checkout -b test //This is shorthand for $ git branch test $ git checkout test