Skip to main content

Git rebase vs Git merge

While working with git and github one will always face the need to combine their changes with the master branch of the team repository. to do this we have two solutions; we either use git merge or git rebase. To explain the differences between these two options we are going to consider the following example, you start working on feature branch for the sidebar of your website and other team members are updating the master branch with new commits. This will result in forked history as shown in the picture below.

A forked commit history

Merge:

We can do the easiest option which is merging the master branch into the sidebar branch with this git command:

git merge sidebar master

This will create a new commit for the merge that connects both of these two branches, giving what looks in the picture below.

Merging master into the feature branch
So as you have seen merging is easy and really simple to work with. It's also a non-destructive operation; by this I mean that the already existing branches are not changes in any way. 

Rebase:

The other option would be rebasing the sidebar branch on top of the master branch using these commands:

git checkout sidebar
gi rebase master

This will move the entirety of the sidebar branch on the tip of the master branch, doing that will incorporate all of the commits in master. But this will re-write all of the commit history because git rebase is a destructive operation.

Comments

Popular posts from this blog

Big O Notation

Big O Notation is a mathematical expression that describes how much time an algorithm takes to run according to the size of it's inputs; mostly concerned about the worst case scenario. Types: 1- Constant Time O(1): On this order, regardless of the number of items, the iterations(time) are constant. Example: const getFirstItem = items =>    items[0]; getFirstITem([1, 2, 3, 4]);  // 1 (one iteration) getFirstItem(['b', 'd', 'g']);   // 'b' (one iteration) 2- Linear Time O(n): On this order, the worst case grows with the number of items. Example: Javascript's built in function indexOf, it loops over an array to find the  correct index of the passed element. The worst case is looping over the whole array. [1, 2, 4, 9, 23, 12].indexOf(12); 3- Quadratic Time O(n ^ 2): For this order, the worst case time is the square of the number of inputs. It grows exponentially according to the number of inputs. Example: Using nested loo...

Deployment In Simple Words

Deployment is the hardest part in the lives of computer coders, it's harder than making apps and games. Any game that you have ever used for example on your computer had to go through many operations to be in the final form it is when you first bought it. The last operation is deployment as you might have guessed. It's about getting your video game ready to use and play on any computer out there. Many issues could happen while deploying the game since we have many environments to deal with these days.

Relational Databases

Relational databases are, well... a collection of data items that have relations between them. These relations are made by associating a one table's primary key with another table's foreign key. It is a great advancement from the old long table that was used to store data which was inefficient in terms of search, memory and space.  And as for normalization; it means a process in which tables are structured to eliminate redundancy and repetition among data and the CRUD operations side-effects. And as a direct result we improve the performance of our queries. An example of a relational database would be two tables; one for student and the other for school. Both of these tables have a column for the school id, and so we make a connection between by assigning the first one as a primary key and the other as foreign key.