5

Originally, there was the master branch.

Then I've create a feature_1 branch from master, to implement feature 1.

After some work on this new branch, I decided to implement feature 2, that depends from feature 1 so I did:

$ git checkout -b feature_2 feature_1 

I did some work on feature_2 branch.

Now, it has no sense to continue developments on feature_1 branch since all its developments are included in feature_2 branch.

Is it "safe" to delete feature_1 branch even if it's the base from which I started feature_2 branch? After the deletion, will I see in the Git graph a single feature_2 branch starting from the master branch?

What I would like to achieve is what written above, a single feature_2 branch starting from master branch at the same point when I started feature_1 branch. Finally, rename it as feature_1_2 branch.

1

2 Answers 2

1

Do:

# Delete branch feature_1 git branch -d feature_1 # Rename feature_2 -> feature_1_2 git branch -m feature_2 feature_1_2 

If you want to make sure that there is no additional work on feature_1 (i.e. commits that are not in feature_2), you can do a fast-forward merge:

git checkout feature_1 git merge --ff-only feature_2 

If the merge succeeds, feature_1 and feature_2 point to the same commit. So it is safe to delete one of them.

Sign up to request clarification or add additional context in comments.

4 Comments

So is it completely safe to delete the branch feature_1 even if feature_2 started from it?
Yes. Unless you have done work on feature_1 after you started feature_2.
No, it's a "dead-end"
I have added some more git-foo to make sure that you'll not lose any work.
0

I think If you delete feature_1, your feature_2 will be lost. So commit feat2 then del feat1

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.