{"id":378,"date":"2014-11-27T15:58:32","date_gmt":"2014-11-27T15:58:32","guid":{"rendered":"http:\/\/www.smr.co.uk\/?p=378"},"modified":"2014-11-27T15:58:32","modified_gmt":"2014-11-27T15:58:32","slug":"git-branching","status":"publish","type":"post","link":"http:\/\/www.smr.co.uk\/?p=378","title":{"rendered":"Git Branching"},"content":{"rendered":"<p>\t\t\t\tI like to use are two kinds of branches, features (aka enhancement \/ story) and issues. A single feature can encapsulate a group of enhancements or even a sprint. We can be flexible here as creating too many branches will slow us down. An issue is a bug, a configuration change or some kind of task that involves a code change.<br \/>\nThe naming convention is:-<br \/>\nfeature-name e.g. feature-add-currency-prices<br \/>\nissue-name e.g. issue-prices-not-appearing<\/p>\n<h3>Seeing which Branches are Available<\/h3>\n<p><code>git branch <\/code><br \/>\nOr for remote branches not in your repository<br \/>\n<code>git branch -a<\/code><\/p>\n<h3>Creating a Branch<\/h3>\n<p>To create a branch on an project that you have previously cloned and as a side effect also switch to the branch<br \/>\n<code>git checkout -b feature-add-currency-prices <\/code><br \/>\nMake some changes, commit them in the usual way. Then push to the repository and add the branch to the repository so that others can see it<br \/>\n<code>git push -u origin feature-add-currency-prices<\/code><br \/>\nAnd simply do<br \/>\n<code>git push<\/code><br \/>\nsubsequently<\/p>\n<h3>Using an Existing Branch<\/h3>\n<p>To switch to an existing branch first make sure you have the latest repo which includes the branch<br \/>\n<code>git pull <\/code><br \/>\nThen checkout the branch and switch to it<br \/>\n<code>git checkout feature-add-currency-prices<\/code><br \/>\nMake git changes and commit in the usual way and then when its time to push<br \/>\n<code>git push -u origin feature-add-currency-prices<\/code><br \/>\nAfter that git remembers your branch so you can simply type<br \/>\n<code>git push<\/code><\/p>\n<h3>Merging to Master<\/h3>\n<p>Finally merge to master<br \/>\n<code>git checkout master<br \/>\ngit pull<br \/>\ngit pull origin feature-add-currency-prices<br \/>\ngit push origin master <\/code><\/p>\n<h3>Merging changes from Master to a branch<\/h3>\n<p><code> git checkout master<br \/>\ngit pull<br \/>\ngit checkout feature-add-currency-prices<br \/>\ngit pull\u00a0origin feature-add-currency-prices<br \/>\ngit merge master<br \/>\n-- there maybe conflicts at this point<br \/>\ngit status<br \/>\n-- after all\u00a0conflicts\u00a0are resolved<br \/>\ngit push\u00a0origin feature-add-currency-prices<br \/>\n<\/code><\/p>\n<h3>Issues<\/h3>\n<p>Eclipse didn&#8217;t do a good job of branching but once the branch is setup it does recognise the branch and can be used for commit and after the first manual push.<\/p>\n<h3>Tags<\/h3>\n<p>To tag the master after a successful test to say v-0.2.6<br \/>\n<code><br \/>\ngit tag -a v-0.2.6 -m 'v-0.2.6'<br \/>\ngit push origin v-0.2.6<br \/>\n<\/code><\/p>\n<h3>Tips<\/h3>\n<p>To see what commits are waiting to be pushed<br \/>\n<code>git log --branches --not --remotes<\/code><br \/>\nFor a list of files to be pushed, run<br \/>\n<code>git diff --stat --cached origin\/master<\/code><br \/>\nTo delete a branch<br \/>\n<code>git branch -d branch_name<\/code><br \/>\nTo remove from origin<br \/>\n<code>git push origin :branch_name<\/code><\/p>\n<h4>References<\/h4>\n<p>https:\/\/www.atlassian.com\/git\/workflows#!workflow-feature-branch<br \/>\nhttp:\/\/reinh.com\/blog\/2009\/03\/02\/a-git-workflow-for-agile-teams.html<br \/>\nhttp:\/\/marklodato.github.io\/visual-git-guide\/index-en.html<br \/>\nhttp:\/\/nvie.com\/posts\/a-successful-git-branching-model<br \/>\nhttp:\/\/rogerdudler.github.io\/git-guide\/\t\t<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I like to use are two kinds of branches, features (aka enhancement \/ story) and issues. A single feature can encapsulate a group of enhancements or even a sprint. We can be flexible here as creating too many branches will &hellip; <a href=\"http:\/\/www.smr.co.uk\/?p=378\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a> <a href=\"http:\/\/www.smr.co.uk\/?p=378\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[11],"tags":[],"class_list":["post-378","post","type-post","status-publish","format-standard","hentry","category-technology"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/www.smr.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/378","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.smr.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.smr.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.smr.co.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.smr.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=378"}],"version-history":[{"count":0,"href":"http:\/\/www.smr.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/378\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.smr.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=378"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.smr.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=378"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.smr.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=378"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}