# Git Rebase Rebasing is often used as an alternative to merging. Rebasing a branch updates one branch with another by applying the commits of one branch on top of the commits of another branch. For example, if working on a feature branch that is out of date with a dev branch, rebasing the feature branch onto dev will allow all the new commits from dev to be included in feature. Here’s what this looks like visually: ### Visualization of the command :   ### Syntax : ```bash git rebase feature dev ``` where branch1 is the branch we want to rebase to the master. ### Difference between Merge and Rebase : Many people think that `Merge` and `Rebase` commands perform the same job but actually they are completely different and we will discuss this in the following lines. - #### Merge : This command is used to integrate changes from some branch to another branch with keeping the merged branch at its base so you can easily return to earlier version of code if you want and the following picture show that :  ### typical use of rebasing #### Updating a Feature Branch Lets say you’re working away on a feature branch, minding your own business.  Then you notice some new commits on dev that you’d like to have in your feature branch, since the new commits may affect how you implement the feature.  You decide to run git rebase dev from your feature branch to get up-to-date with dev. However when you run the rebase command, there are some conflicts between the changes you made on feature and the new commits on dev. Thankfully, the rebase process goes through each commit one at a time and so as soon as it notices a conflict on a commit, git will provide a message in the terminal outlining what files need to be resolved. Once you’ve resolved the conflict, you git add your changes to the commit and run git rebase --continue to continue the rebase process. If there are no more conflicts, you will have successfully rebased your feature branch onto dev.  Now you can continue working on your feature with the latest commits from dev included in feature and all is well again in the world. This process can repeat itself if the dev branch is updated with additional commits. - #### Rebase : On the other hand `Rebase` command is used to transfer the base of the branch to be based at the last commit of the current branch which make them as one branch as shown in the picture at the top. ### Rebasing interactively : You can also rebase a branche on another `interactively`. This means that you will be prompted for options. The basic command looks like this: ```bash git rebase -i feature main ``` This will open your favorite editor (probably `vi` or `vscode`). Let's create an example: ```bash git switch main git checkout -b feature-interactive echo "
Rebasing interactively is super cool
" >> feature1.html git commit -am "Commit to test Interactive Rebase" echo "With interactive rebasing you can do really cool stuff
" >> feature1.html git commit -am "Commit to test Interactive Rebase" ``` So you are now on the `feature-interactive` branch with a commit on this branch that doesn't exist on the `main` branch, and there is a new commit on the `main` that is not in your branch. Now using the interactive rebase commande: ```bash git rebase -i main ``` Your favorite editor (`vi` like here or `vscode` if you've set it up correctly) should be open with something like this: ``` pick a21b178 Commit to test Interactive Rebase pick cd3400c Commit to test Interactive Rebase # Rebase 1d152d4..a21b178 onto 1d152d4 # # p, pick