Yes, you need to rebase your copy of feature/other-feature
. However, in this case a simple git rebase develop
will probably not work, because you branched off another feature branch, instead of directly off develop
. You need to use rebase --onto
:
git rebase --onto develop feature/earlier-feature feature/other-feature
Here, feature/earlier-feature
is the feature branch you had checked out when you die the original
git checkout -b feature/other-feature
.
This rebase will:
- Take the commits in
feature/other-feature
which are not infeature/earlier-feature
. - Re-apply these commits to
develop
.
You should end up with a changed branch feature/other-feature
which is now based on develop
.
Notes
- Because of the rebasing you will have to force-push your branch to your GitHub repository. This is not a problem, as long as you have the only clone of your repository. If you use the repo with others, things are more difficult (see below).
- The rebase may cause conflicts. You will have to resolve these manually.
- Further reading: The concepts behind rebasing, and the meaning of
rebase --onto
are well explained in the book "Pro Git". See chapter 3.6, Git Branching - Rebasing.
If others have cloned your repository
You write
But given that I've pushed my mistake to origin and other people have clones of this repo, do I need to rebase or do something else?
You can still rebase as described above. However, you must not force-push the rebased branch under the old name. Instead, create a copy of the branch:
git checkout -b feature/other-feature-2 feature/other-feature
This will create a new branch feature/other-feature-2
that is an exact copy of feature/other-feature
. You can then rebase the new branch, and push it under the new name.
Then tell everyone that feature/other-feature
has been superseded by feature/other-feature-2
, and delete feature/other-feature
on GitHub. Having to tell everyone is the price you pay for rebasing :-).