• In software development, there is always an endless number of new features to be added.
  • When you add a new feature, you don’t want to mess up the main branch with some experimental code, so every time you add a new feature, it’s best to create a new onefeatureBranch, develop on top, when done, merge, and finally, delete thatfeatureBranch.
  • Now, you’ve finally been given a new assignment: development code nameVulcanThe new feature is planned for the next generation of starships.
  • So prepare to develop:
$ git switch -c feature-vulcan
Switched to a new branch 'feature-vulcan'
Copy the code
  • After 5 minutes, the development is complete:
$ git add vulcan.py

$ git status
On branch feature-vulcan
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

	new file:   vulcan.py

$ git commit -m "add feature vulcan"
[feature-vulcan 287773e] add feature vulcan
 1 file changed, 2 insertions(+)
 create mode 100644 vulcan.py
Copy the code
  • Cut backdev, preparing to merge:
$ git switch dev
Copy the code
  • If all goes well, the feature and bug branches are similar, merged and then deleted.

But!

  • At this time, received orders from superiors, because of insufficient funds, the new function must be cancelled!
  • It was all for nothing, but the branch containing classified information had to be destroyed on site:
$ git branch -d feature-vulcan
error: The branch 'feature-vulcan' is not fully merged.
If you are sure you want to delete it, run 'git branch -D feature-vulcan'.
Copy the code
  • Destruction failed. Git Git Git Git Git Git Git Git Git Git Git Git Git Git Git Git Git Git
  • Now we forcibly delete:
$ git branch -D feature-vulcan
Deleted branch feature-vulcan (was 287773e).
Copy the code

Finally deleted!

summary

  • Develop a newfeature, preferably create a new branch;
  • If you want to discard a branch that has not been merged, passgit branch -D <name>Forcibly delete.