git - why should I delete feature branches when merged to master -


most of git workflows i've seen suggest delete branch after it's been merged master. example, gitflow suggests following:

# incorporating finished feature on develop  $ git checkout develop switched branch 'develop' $ git merge --no-ff myfeature updating ea1b82a..05e9557 (summary of changes) $ git branch -d myfeature deleted branch myfeature (was 05e9557). $ git push origin develop 

why should delete branch? i'm curios when later bug discovered introduced feature - should create branch same name again, fix bug there, merge master , again delete branch?

something important realize git branches nothing more label pointing commit. branching in git literally branching. here's repository looks if feature branched off master when master commit b.

a - b - c - f - h [master]      \       d - e - g - i[feature] 

see? actual branch. when git merge feature master, this.

a - b - c - f - h - j [master]      \             /       d - e - g -  [feature] 

and once git branch -d feature branch history remains!

a - b - c - f - h - j [master]      \             /       d - e - g - 

j has parents h , i. j cannot exist without them, it's baked how git works. cannot exist without g. g cannot exist without e. , on. branch must remain

j merge commit typically contain name of branch being merged. other commit, can add more information it, link issue tracker.

git merge --no-ff used prevent git doing "fast forward" , losing branch history. happens if no work has been done on master since branch created. fast-forward looks this.

a - b[master]- d - e - g - [feature]  git checkout master git merge feature  - b - d - e - g - [feature] [master] 

since master direct ancestor of feature, no merge required. git can move master label. branch history lost, looks d, e, g , done individual commits on master. git merge --no-ff tells git never this, perform merge.

in future, when it's noticed bug introduced in g, browsing repository can see done part of branch, ahead find merge commit, , information branch there.

even so, why delete branch? 2 reasons. first, clutter list of branches dead branches.

second, , more important, prevents reusing branch. branching , merging complicated. single use, short lived feature branches simplify process ensuring ever merge branch master once. eliminates many technical , management problems. when merge branch, done. if need fix problem introduced in branch, treat bug in master , make new branch fix it.

unfortunately, git log lies user , presents linear representation of history not linear. fix this, use git log --graph --decorate. draw lines in examples above, , show branches , tags on each commit. you'll truer view of repository.

if you're on mac, gitx visualize repository you. gitk generic version.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -