once
once

Reputation: 702

Usage of git rebase

Suppose I have a feature branch which is created from a development branch.

After some time, there are new commits to the development branch.

I want to apply those commits back to my feature branch so that it is as if my feature branch is based on the latest development branch.

To do so, as it to use the following git command ?

git pull origin //getting all latest updates
git checkout -b my-feature-branch //navigate to my feature branch
git rebase development //apply those delta commits back to my feature branch

Upvotes: 0

Views: 143

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 522762

You should be following these steps, assuming you are starting off on the feature branch:

git fetch origin                 # update origin/development with latest changes
git rebase origin/development    # rebase on latest development
# resolve conflicts, etc.
git push --force origin feature  # overwrite remote feature with local version

Note that I avoid doing a git pull here, since by default that might be doing a merge somewhere, which you probably don't want. Also, notice in the final step we are doing a force push. This is required as the history of feature has been rewritten. Therefore, a regular (non force) push would fail as the histories do not line up properly.

Upvotes: 1

Related Questions