Yimin Rong
Yimin Rong

Reputation: 2027

git - use an existing branch, but copy latest from current branch to it

We have a feature branch (feature) that was used a while ago. The changes from feature were integrated back to the development branch (development). But since then, development has been revised, and feature hasn't, i.e. it has old code. We are revisiting the same feature and would like to reuse this branch. How do we make sure feature = development?

I'm guessing there is probably a duplicate question out there, but I'm just missing the correct terminology.

Upvotes: 2

Views: 116

Answers (2)

vonbrand
vonbrand

Reputation: 11831

If you just want to discard the old feature branch:

git checkout master              # Make sure we are there
git branch -d feature            # Kill old branch dead
git checkout -b feature          # New feature branch, starting at current master

But in that case, I'd just leave it lying around (or perhaps rename it to historic/feature or such) and just create a new branch for the spanking new feature.

Other options are to rebase feature on top of master (basically, grafting it on there; changes already applied should just take over).

git tag feature save-this-just-in-case   # History rewriting might lose it...
git checkout feature
git rebase master

Be careful, branches off feature won't follow it around!

Or even just merge the changes in master into feature:

git checkout feature
git merge master

PS: Before blindly following advise from somebody at the other end of the world posting (semi)anonymously on some random site, read the manuals and do some experiments with a scratch (copy of the) repository.

Upvotes: 1

Math
Math

Reputation: 2436

You should merge the branches with git merge development from the feature branch.
If you did not change feature it will simply fast-forward to development. Otherwise, simply solve the merging conflicts.

Upvotes: 5

Related Questions