Leon Chaewon Kong's dev blog

6 Steps to Use Git Rebase in Your Projects

Consider, there is two branches main and develop.

I need to add authentication api. Then I will create new branch from develop.

1. Create Feature Branch

# First, change base branch to develop
$ git checkout develop

# Next, create new feature branch from develop
$ git checkout -b feature/auth-api

2. Make Changes And Commit the Changes

Then, I might commit some changes and updates. Add new api, add configurations. Do whatever is needed.

git add [CHANGED FILENAME]
git commit -m "[YOUR COMMIT MESSAGE]"

3. Rebase

After committing all changes, now is the time to rebase.

git pull --rebase origin develop

which rebases your base commit, conforming to origin.

4. Push the Changes

Then, push your changes to the remote.

git push origin feature/auth-api

Create a pull request, get some code reviews, and merge your pull requrest.

5. Pull Origin

Next, checkout develop and pull the origin.

git checkout develop
git pull origin develop

6. Remove Feature Branch

Finally, remove the feature branch.

$ git branch -D feature/auth-api

# Tell remote about deleting the feature branch.
$ git push origin --delete feature/auth-api