quickblueblur
quickblueblur

Reputation: 286

How can I branch from another branch, then delete origin branch?

I have two main branches: master and develop.

My usual workflow on a new feature is:

  1. Create a new branch from develop: git checkout -b <myfeature> develop
  2. Code and test the feature
  3. Commit the changes: git commit -a -m "<message>"
  4. Change back to develop: git checkout develop
  5. Merge the feature back into develop: git merge --no-ff <myfeature>
  6. Delete the branch: git branch -d <myfeature>
  7. Push develop to remote: git push origin develop

Now I need to work on a new feature that requires the current feature. My new workflow would be:

  1. Create a new branch from develop: git checkout -b <myfeature> develop
  2. Code and test the feature
  3. Commit the changes: git commit -a -m "<message>"
  4. QA is currently validating
  5. Create a new branch from myfeature: git checkout -b <newfeature> <myfeature>
  6. Start coding newfeature
  7. QA is done validating, commit current code: git commit -a -m "<message>"
  8. Change back to develop: git checkout develop
  9. Merge the feature back into develop: git merge --no-ff <myfeature>
  10. Delete the branch: git branch -d <myfeature>
  11. Push develop to remote: git push origin develop
  12. Change back to newfeature: git checkout newfeature
  13. Finish coding newfeature
  14. Commit the changes: git commit -a -m "<message>"
  15. Change back to develop: git checkout develop
  16. Merge the feature back into develop: git merge --no-ff <newfeature>
  17. Delete the branch: git branch -d <newfeature>
  18. Push develop to remote: git push origin develop

Is this a proper workflow? Is there any repercussions to deleting the branch in step 10 (i.e. does it orphan newfeature?)?

The original guidelines were from Vincent Driessen's A successful Git branching model. I also read Create a branch in Git from another branch, but it doesn't really get into deleting the branch that spawned the new branch.

Upvotes: 1

Views: 2689

Answers (2)

bro
bro

Reputation: 61

Nothing wrong with that.

Just be sure to manage those states with a little caution. Lets say. You work on A and clone B. But you need to do some changes on A after business found something they want to have changed. If you push A and want those changes now in B, git merge might result in duplicate commits. Instead use git rebase.

I am working solely with trunk-based development. https://trunkbaseddevelopment.com/

Upvotes: 1

Acorn
Acorn

Reputation: 26066

Is this a proper workflow?

That depends on what you want to achieve. There are many possible workflows.

Is there any repercussions to deleting the branch in step 10 (i.e. does it orphan newfeature?)?

Branches are just pointers to a commit, they do not depend on each other. Deleting a branch removing that entry point to the graph, but it does not remove the commits by itself. As long as you have a way to go back to that commit from another branch, the commits will never be removed.

Upvotes: 5

Related Questions