Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
November 29, 2021 08:20 am GMT

Use GIT REBASE instead of GIT MERGE

In this quick post, I want to show how to use git rebase to keep your commit path clean and maintainable.

What is git rebase?

It behaves like merging by applying all changes from the target branch but not creating an extra commit for that where it keeps the commit log clean and readable. Simply, it takes your new commits at puts them at the very top of commit log.

Let's assume that you're implementing a new feature by creating a new branch from the master. Meanwhile, you're co-workers also working on other features and some of them already merged their PRs to master branch.

At this point, your branch will be no longer up-to-date with master so you need to apply those changes before attempting to create any pull request.

Usually, there're two options for such cases:

Using git merge
Using git rebase

Let's say you decide to use git merge to apply changes from master where it will create an extra commit for each merging. Imagine how messy the git log will be if we continuously use merging to keep our branch up-to-date. It also makes hard to track real commits since the majority of them will be created automatically by merging.

Example scenario

Assume that we want to rebase with the master branch to apply most recent changes:

git rebase master

If there will be any conflicts while rebasing, then you have to resolve them and also adding changes once you finished:

git add -ugit rebase --continue

In case you decided to abort the process:

git rebase --abort

Once rebasing finished, you will able to see new changes in your branch.

I prefer to avoid git merge at all except in PRs where it have to merge with master by creating a commit about it. So, when analyzing git log it will be much easier to understand purpose of commits.

Video Explanation


Original Link: https://dev.to/thepylot/use-git-rebase-instead-of-git-merge-3c1c

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To