{"id":3208,"date":"2011-03-04T01:35:24","date_gmt":"2011-03-03T20:05:24","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=3208"},"modified":"2016-12-19T15:30:06","modified_gmt":"2016-12-19T10:00:06","slug":"git-branching-model-choose-branches-for-deletion-see-whats-remaining-for-the-merge","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/git-branching-model-choose-branches-for-deletion-see-whats-remaining-for-the-merge\/","title":{"rendered":"git branching model: choose branches for deletion &#8211; see whats remaining for the merge"},"content":{"rendered":"<p>This post is for people who are already familiar with Git and work on multiple branches (esp. feature branches).<br \/>\nBy practice, feature branches are the branches created from a root branch (master or any other as per your branching model) and once feature is complete\/tested &#8211; they are merged back into the same root branch.<\/p>\n<p>\nWorking in such a manner is pretty nice and clean. But things start getting messy if we don&#8217;t delete the branches on time (esp. after merging into root branch). In that case when we run command &#8211;<br \/>\n[groovy]<br \/>\n     git branch<br \/>\n[\/groovy]<br \/>\nIt shows us zillions of branches and we start getting feeling to get a rid of all futile branches. But we don&#8217;t know which branches are already merged and which are still under progress or yet to be tested.<br \/>\n<\/p>\n<p><b>Solution to this problem<\/b>:<br \/>\n[groovy]<br \/>\n      # I am assuming that your root branch is master<br \/>\n      git checkout master<br \/>\n      git branch &#8211;merged<br \/>\n[\/groovy]<br \/>\n<\/p>\n<p>Above command will show you all branches which are already merged into the current branch (master branch in this case). This means you can delete these (feature) branches now.<br \/>\nFor deleting a branch on local: git branch {-d | D} &#8216;feature-branch-1&#8217;<br \/>\nFor deleting from remote: git push origin :feature-branch-1<br \/>\nI assumed that origin is your remote.<\/p>\n<p>Similarly if you run<br \/>\n[groovy]<br \/>\n      git branch &#8211;no-merged<br \/>\n[\/groovy]<br \/>\nIt will give a list of branches which are yet to be merged.<\/p>\n<p>\n<b>Question<\/b>: I got a list of branches which are not merged yet. Now I want to see the commits in particular branch which are not merged into root branch yet?<br \/>\n<b>Solution<\/b>:<br \/>\n[groovy]<br \/>\n      git log &#8211;pretty=oneline maser..branch1<br \/>\n[\/groovy]<br \/>\nAgain, master is your root branch. And branch1 is your feature branch having commits yet to be merged.<\/p>\n<p>Your comments are always Welcome. Please post if you have any!<\/p>\n<p>Cheers!<br \/>\nSalil Kalia<br \/>\nSalil [at] IntelliGrape [dot] com<br \/>\nTwitter LinkedIn <\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post is for people who are already familiar with Git and work on multiple branches (esp. feature branches). By practice, feature branches are the branches created from a root branch (master or any other as per your branching model) and once feature is complete\/tested &#8211; they are merged back into the same root branch. [&hellip;]<\/p>\n","protected":false},"author":17,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":0},"categories":[7],"tags":[375,387],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/3208"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=3208"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/3208\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=3208"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=3208"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=3208"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}