How to Use Git Rebase in a Practical Situation

Let’s say there are two pull requests open on a project repository.
Each change has its own branch like this:

  • master
  • feature/add-base64-endpoint
  • feature/add-user-agent-endpoint

The challenge is to use git rebase to add both changes to master. When you finished, your master branch should have three commits in the following order:

  • feat: add user-agent endpoint
  • feat: add base64 endpoint
  • init

Okay, let’s go!

 1git clone repo_url
 2git status
 3git checkout feature/add-base64-endpoint
 4git rebase master
 5git status
 6git checkout master
 7git merge feature/add-base64-endpoint
 8git status
 9git checkout feature/add-user-agent-endpoint
10git rebase master

Oops! You should see rebase conflict!
You need to check the code and fix it. Fortunately VS Code provides great hints for you to do that.
Once you fix it, do like this:

1git add .
2git rebase --continue
3git checkout master
4git status
5git checkout master
6git merge feature/add-user-agent-endpoint
7git status
8git log

Boom! You must be done!
Happy gitting! 😉

comments powered by Disqus