{"id":1649,"date":"2016-09-13T13:28:38","date_gmt":"2016-09-13T20:28:38","guid":{"rendered":"http:\/\/10kdev.net\/?p=1649"},"modified":"2016-09-13T14:27:12","modified_gmt":"2016-09-13T21:27:12","slug":"git-tags-local-and-remote-be-careful","status":"publish","type":"post","link":"http:\/\/10kdev.net\/?p=1649","title":{"rendered":"Git Tags Local And Remote: Be. Careful."},"content":{"rendered":"<p><img decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/10kdev.net\/wp-content\/uploads\/2016\/09\/46b578f3136d1848b9d3a70d72b5d038.png\" \/><\/p>\n<p>If you are a daily developer like me, but not a release manager, getting called on to do release activities can be a frustrating thing. \u00a0One of those things can be believing your tool&#8217;s view.<\/p>\n<blockquote><p><strong>Be careful &#8211; if you&#8217;ve updated your git tags &#8211; local SourceTree will show git tags at a spot that is not the same place as bitbucket if you do not do a discrete push\u00a0to remove the tag first.<\/strong><\/p><\/blockquote>\n<p>I learned this when I had tagged a release, but then two changes\u00a0came in before we actually did the production deployment and it was requested that I move the tag before we deployed. \u00a0The moved tag was to be the build devops would pull.<\/p>\n<p>So here&#8217;s how it went . . . (general scenario):<\/p>\n<ul>\n<li>Code spot from our develop branch to merge into release branch at checkin #171.<\/li>\n<li>Tag the code v4.5.0<\/li>\n<\/ul>\n<p>To do this was relatively easy, using either SourceTree or command line:<\/p>\n<pre><code>$ git tag v4.5.0\r\n$ git push\r\n<\/code><\/pre>\n<p>Then list them<\/p>\n<pre><code>$ git tag\r\nv4.3.0\r\nv4.4.0\r\nv4.4.1\r\nv4.5.0<\/code><\/pre>\n<p>Now we had a build. \u00a0But wait &#8212; the two changes came in:<\/p>\n<ul>\n<li>checkin #170 to be reverted<\/li>\n<li>checkin #172 hotfix due to something QA found<\/li>\n<\/ul>\n<p>Now don&#8217;t ask me why in this process we jusst didn&#8217;t wait, but, some places follow this process. (The old days we build an artifact, these days on most systems we tag the repo and build, build, build).<\/p>\n<p>The request comes in &#8212; move the tag past these changes!<\/p>\n<p>So I merge these particular fixes into our release branch. \u00a0And the request to move the tag comes in; sounds simple enough.<\/p>\n<pre><code>$ git tag -d v4.5.0\r\n$ git tag v4.5.0\r\n$ git push\r\n<\/code><\/pre>\n<p>Bow SourceTree is reporting on BOTH REMOTE AND LOCAL release instances that the tag has been moved but you know what? When I go and look out on Bitbucket I see:<\/p>\n<pre style=\"padding-left: 30px;\"><code>checkin #172\r\ncheckin revert #170\r\ncheckin #171 v4.5.6 <\/code><\/pre>\n<p>Right. The tag didn&#8217;t move! \u00a0Notably, the gui was *probably* reporting an interesting error about the tag already existing but I did a command line push, and\u00a0the branches looked tagged properly. \u00a0However\u00a0I forgot to do one thing &#8212; push the delete first, then retag, then push again.<\/p>\n<pre><code>$ git tag -d v4.5.0\r\n$ git push\r\n$ git tag v4.5.0\r\n$ git push\r\n<\/code><\/pre>\n<p>Now Bitbucket shows this, correctly:<\/p>\n<pre style=\"padding-left: 30px;\"><code>checkin #172 v4.5.0\r\ncheckin revert #170\r\ncheckin #171 \r\n<\/code><\/pre>\n<p>Lessons?<\/p>\n<ol>\n<li>Don&#8217;t believe your GUI tool &#8212; always check the target repo to make sure.<\/li>\n<li>There may be errors being reported by your gui &#8212; take them seriously and fix them.<\/li>\n<li>Get another developer eyes on it just to make sure.<\/li>\n<li>If you do not do this regularly &#8212; as many of us do not &#8212; be very very meticulous and be very atomic.<\/li>\n<\/ol>\n<p>Git tags are an interesting beast. They are very flexible. And are subject to not obeying compound changes (delete, recreate) in a single action so be careful.<\/p>\n<p><em>Further Reading<\/em><\/p>\n<p><a href=\"https:\/\/git-scm.com\/book\/en\/v2\/Git-Basics-Tagging\">https:\/\/git-scm.com\/book\/en\/v2\/Git-Basics-Tagging<\/a><\/p>\n<p><a href=\"https:\/\/confluence.atlassian.com\/bitbucket\/how-do-i-remove-or-delete-a-tag-from-a-git-repo-282175551.html\">https:\/\/confluence.atlassian.com\/bitbucket\/how-do-i-remove-or-delete-a-tag-from-a-git-repo-282175551.html<\/a><\/p>\n<p><a href=\"http:\/\/stackoverflow.com\/questions\/1125968\/how-to-force-git-pull-to-overwrite-local-files\">http:\/\/stackoverflow.com\/questions\/1125968\/how-to-force-git-pull-to-overwrite-local-files<\/a><\/p>\n<p><a href=\"http:\/\/stackoverflow.com\/questions\/19298600\/tag-already-exists-in-the-remote-error-after-recreating-the-git-tag\">http:\/\/stackoverflow.com\/questions\/19298600\/tag-already-exists-in-the-remote-error-after-recreating-the-git-tag<\/a><\/p>\n<p><a href=\"http:\/\/stackoverflow.com\/questions\/8044583\/how-can-i-move-a-tag-on-a-git-branch-to-a-different-commit\">http:\/\/stackoverflow.com\/questions\/8044583\/how-can-i-move-a-tag-on-a-git-branch-to-a-different-commit<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you are a daily developer like me, but not a release manager, getting called on to do release activities can be a frustrating thing. \u00a0One of those things can be believing your tool&#8217;s view. Be careful &#8211; if you&#8217;ve updated your git tags &#8211; local SourceTree will show git tags at a spot that [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/posts\/1649"}],"collection":[{"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/10kdev.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1649"}],"version-history":[{"count":3,"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/posts\/1649\/revisions"}],"predecessor-version":[{"id":1652,"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/posts\/1649\/revisions\/1652"}],"wp:attachment":[{"href":"http:\/\/10kdev.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1649"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/10kdev.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1649"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/10kdev.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1649"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}