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 w…


This content originally appeared on DEV Community and was authored by ThePylot

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 -u
git 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


This content originally appeared on DEV Community and was authored by ThePylot


Print Share Comment Cite Upload Translate Updates
APA

ThePylot | Sciencx (2021-11-29T08:20:49+00:00) Use GIT REBASE instead of GIT MERGE. Retrieved from https://www.scien.cx/2021/11/29/use-git-rebase-instead-of-git-merge/

MLA
" » Use GIT REBASE instead of GIT MERGE." ThePylot | Sciencx - Monday November 29, 2021, https://www.scien.cx/2021/11/29/use-git-rebase-instead-of-git-merge/
HARVARD
ThePylot | Sciencx Monday November 29, 2021 » Use GIT REBASE instead of GIT MERGE., viewed ,<https://www.scien.cx/2021/11/29/use-git-rebase-instead-of-git-merge/>
VANCOUVER
ThePylot | Sciencx - » Use GIT REBASE instead of GIT MERGE. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/11/29/use-git-rebase-instead-of-git-merge/
CHICAGO
" » Use GIT REBASE instead of GIT MERGE." ThePylot | Sciencx - Accessed . https://www.scien.cx/2021/11/29/use-git-rebase-instead-of-git-merge/
IEEE
" » Use GIT REBASE instead of GIT MERGE." ThePylot | Sciencx [Online]. Available: https://www.scien.cx/2021/11/29/use-git-rebase-instead-of-git-merge/. [Accessed: ]
rf:citation
» Use GIT REBASE instead of GIT MERGE | ThePylot | Sciencx | https://www.scien.cx/2021/11/29/use-git-rebase-instead-of-git-merge/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.