Git Tag https://www.novicedev.com/ en How to Create a new GIT Branch from a Tag? https://www.novicedev.com/blog/how-create-new-git-branch-tag <span>How to Create a new GIT Branch from a Tag?</span> <div class="field field--name-field-image field--type-image field--label-hidden field-item"> <img loading="lazy" src="/sites/novicedev/files/styles/blog_cover/public/2022-09/create-git-branch-from-tag_0.png?itok=hC7ESngi" width="772" height="435" alt="How to Create a new GIT Branch from a Tag?" title="How to Create a new GIT Branch from a Tag?" class="image-field" /> </div> <span><span>noviceadmin</span></span> <span>Sun, 09/18/2022 - 15:10</span> <div> <div class="field-item"> <div class="paragraph paragraph--type--text paragraph--view-mode--default"> </div> </div> </div> <div class="field field--name-body field--type-text-with-summary field--label-hidden field-item"><p><strong>A new GIT branch can be created from a tag through the “git checkout” command with the “-b” option followed by a new branch name and tag name.</strong></p> <pre> <code class="language-bash">$ git checkout -b &lt;new-branch&gt; &lt;tag-name&gt;</code></pre> <p> </p> <h2>Why Create Git Branch from a Tag</h2> <p><a href="https://www.novicedev.com/blog/how-create-git-tags-examples">GIT tags are created</a> to mark a specific point in git history and then deployed. But sometimes you might want to debug the deployed code and the best way is to create a new GIT branch from that tag.</p> <p> </p> <h2>How to Create Git Branch from a Tag</h2> <p>Let’s say you have deployed tag v2.0 on production and now you have some issues after the deployment.</p> <p>Now creating a debug branch from the tag v2.0 will be the best way to make sure you have the exact code which is deployed on production.</p> <p>Now let's go through each step one by one to create a new branch from the correct tag.</p> <h3>1. Get the tag</h3> <p>Make sure you fetch all the tags from your remote repository with the "git fetch" command</p> <pre> <code class="language-bash">$ git fetch --all --tags</code></pre> <h3>2. Confirm the tag</h3> <p>Now confirm that you have fetched the required tag v2.0 from which you want to create the branch.</p> <pre> <code class="language-bash">$ git tag -l v2.0 v1.0</code></pre> <h3>3. Create a new branch from the tag</h3> <p>After confirming that tag v2.0 fetch properly, we can now run the "git checkout" command to create the new branch from that tag.</p> <pre> <code class="language-bash">$ git checkout -b debug-tag-2-0 v2.0</code></pre> <p>Now we have a new branch "debug-tag-2-0" ready for debugging on local.</p> <p> </p> <h2><strong>Conclusion</strong></h2> <p>In this tutorial, we learned why we might need to create a new git branch from a tag for debugging and how this can be achieved with the "git checkout" command.</p> </div> <div class="node-taxonomy-container"> <ul class="taxonomy-terms"> <li class="taxonomy-term"><a href="/topic/git" hreflang="en">Git</a></li> <li class="taxonomy-term"><a href="/topic/git-checkout" hreflang="en">Git Checkout</a></li> <li class="taxonomy-term"><a href="/topic/git-tag" hreflang="en">Git Tag</a></li> </ul> </div> <!--/.node-taxonomy-container --> <section id="node-article-comment" id="comments"> <h2 class="comments-title">Comments</h2> <article data-comment-user-id="0" id="comment-3025" class="js-ajax-comments-id-3025 js-comment comment comment-by-anonymous"> <header class="comment-header"> <div class="comment-user-picture"> </div><!-- /comment-user-picture --> <div class="comment-meta"> <h3 class="comment-title"><a href="/comment/3025#comment-3025" class="permalink" rel="bookmark" hreflang="en">Hello novicedev.com…</a></h3> <p><span>Christine Fuller</span> Sat, 03/11/2023 - 04:38 <mark class="hidden" data-comment-timestamp="1684509156"></mark></p> </div><!-- /comment-meta --> </header> <div class="comment-body"> <div class="field field--name-comment-body field--type-text-long field--label-hidden field-item"><p>Hello novicedev.com webmaster, Well done!</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=3025&amp;1=default&amp;2=en&amp;3=" token="bzaOCQoOyamrUZqA7CE7Mn9ZJFFlnzz5PlJfIuNU9KM"></drupal-render-placeholder> </div> <!-- /.comment-body --> </article> <div class="comment-form-wrap"> <h2 class="add-comment-title">Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=29&amp;2=comment&amp;3=comment" token="UMnLAd2pwczbhuG_AINUbJsxrKQK2Tp-jz6Pxzped2E"></drupal-render-placeholder> </div> <!--/.comment-form --> </section> Sun, 18 Sep 2022 15:10:55 +0000 noviceadmin 29 at https://www.novicedev.com How to create git tags (With Examples) https://www.novicedev.com/blog/how-create-git-tags-examples <span>How to create git tags (With Examples)</span> <span><span>noviceadmin</span></span> <span>Fri, 10/23/2020 - 07:23</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field-item"><p><span><span><span><span><span><span>Git tag is used to mark a specific point in the git history. And are mostly <strong>used for creating project releases</strong>.</span></span></span></span></span></span></p> <p><span><span><span><span><span><span>Git tags are similar to git branches but <strong>no change can be made once a tag is created</strong>.</span></span></span></span></span></span></p> <p><span><span><span><span><span><span>In this tutorial, you will learn about <strong>how to create new git tags</strong> for your project.</span></span></span></span></span></span></p> <h2><span><span><span><span><span><span>Create a new git tag</span></span></span></span></span></span></h2> <p><span><span><span><span><span><span>The simplest and most straightforward way to <strong>create a new tag is by running the “git tag” command with the tag name</strong>.</span></span></span></span></span></span></p> <pre> <code>$ git tag &lt;tag_name&gt;</code></pre> <p>The above syntax can be used to create a tag by replacing &lt;tagname&gt; with the actual tag name.</p> <p>Here is an example of how someone might use this git command in real life to create a tag.</p> <pre> <code>$ git tag v1.0</code></pre> <p><span><span><span><span><span><span>In the above example “v1.0” is the name of your new git tag.</span></span></span></span></span></span></p> <h2><span><span><span><span><span><span>Create a git tag from a commit</span></span></span></span></span></span></h2> <p><span><span><span><span><span><span><strong>Git tag can also be created from a particular <a href="https://git-scm.com/book/en/v2/Git-Internals-Git-Objects">commit SHA</a> from git history.</strong> You can use the “git tag” command with the tag name and commit SHA for which tag need is created.</span></span></span></span></span></span></p> <p><span><span><span><span><span><span>Syntax to create git tag from a commit:</span></span></span></span></span></span></p> <pre> <code>$ git tag &lt;tag_name&gt; &lt;commit_sha&gt;</code></pre> <p><span><span><span><span><span><span><strong>Example to create a git tag</strong> from a commit:</span></span></span></span></span></span></p> <pre> <code>$ git tag v1.0 c69d03e</code></pre> <p><span><span><span><span><span><span>If you want to <strong>create a tag from the last commit</strong> then you can simply use a HEAD option as shown below.</span></span></span></span></span></span></p> <pre> <code>$ git tag v1.0 HEAD</code></pre> <p><span><span><span><span><span><span>Git tag can also be <strong>created from the commit SHA with an annotation</strong> tag by adding “-a” and “-m” options.</span></span></span></span></span></span></p> <pre> <code>$ git tag -a &lt;tag_name&gt; &lt;commit_sha&gt; -m "Your message"</code></pre> <p> </p> <h2><span><span><span><span><span><span>View available git tags</span></span></span></span></span></span></h2> <p><span><span><span><span><span><span>Once the tag is created you can just <strong>run the “git tag” command to confirm the tag</strong> and get all the tag you have available.</span></span></span></span></span></span></p> <pre> <code>$ git tag v1.0 v2.0 v3.0</code></pre> <p> -l option can be added to "git tag" command to further refine the result if you have a big list of tags. For example, if you only want to see tags for v2.0 and sub-releases.</p> <pre> <code>$ git tag -l "v2.*" v2.0 v2.5</code></pre> <p> </p> <h2>Type of git tags</h2> <p><span><span><span><span><span><span>As now we know what are git tags and why we need them, let’s talk about the <strong>type of tags git supports</strong>. You can have <strong>two types of tags in git, one is Lightweight Tags and another is Annotated Tags</strong>.</span></span></span></span></span></span></p> <p> </p> <h2><span><span><span><span><span><span>Lightweight Tags</span></span></span></span></span></span></h2> <p><span><span><span><span><span><span>As the name suggests <strong>Lightweight Tags is the simpler and trimmed down version of creating a tag without any meta-information</strong> about the tag. The example you have seen above is the example of Lightweight Tags, and here is the syntax again.</span></span></span></span></span></span></p> <pre> <code>$ git tag &lt;tag_name&gt;</code></pre> <p> </p> <h2><span><span><span><span><span><span>Annotation Tags</span></span></span></span></span></span></h2> <p><span><span><span><span><span><span><strong>Annotation Tags are a method of creating a git tag with some extra meta information.</strong> To create an annotation tag you just need to add “-a” with the git tag command and “-m” to specify the message.</span></span></span></span></span></span></p> <pre> <code>$ git tag -a v1.0 -m “Release v1.0 create.”</code></pre> <p><span><span><span><span><span><span>And now you can <strong>use the “git show” command to see all the data attached with the tag</strong> we just created with annotation.</span></span></span></span></span></span></p> <pre> <code>$ git show v1.0 tag v1.0 Tagger: John Corner &lt;[email protected]&gt; Date:   Sun Oct 25 16:41:00 2020 +0800 Release v1.0 created. commit c69d03eaf212510534a3d79f98ff36bb4b018a81 (HEAD -&gt; master, tag: v1.0, origin/master) Merge: 83633c99e 0714ce67b Author: John Corner &lt;[email protected]&gt; Date:   Sun Oct 18 04:42:24 2020 +0000</code></pre> <p> </p> <h2>Conclusion</h2> <p>So in this blog post, we learned about how to <strong>create a git tag for your project release with examples</strong>.</p> <p>We also covered how to create a git tag from a commit SHA and how to view the created git tags. Later we cover Lightweight tags and Annotation tags with examples.</p> <p> </p> <p>You can read further about git tags in the following articles:</p> <ul> <li><a href="/blog/how-push-git-tag-remote-example">How to push git tag to remote (With example</a>)</li> <li><a href="/blog/how-delete-git-tag-local-and-remote-examples">How to delete git tag from local and remote (With Examples)</a></li> </ul> </div> <div class="node-taxonomy-container"> <ul class="taxonomy-terms"> <li class="taxonomy-term"><a href="/topic/git" hreflang="en">Git</a></li> <li class="taxonomy-term"><a href="/topic/git-tag" hreflang="en">Git Tag</a></li> </ul> </div> <!--/.node-taxonomy-container --> <section id="node-article-comment--2" id="comments"> <div class="comment-form-wrap"> <h2 class="add-comment-title">Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=7&amp;2=comment&amp;3=comment" token="XclDo4EBJ-co3K9OihriJH27UPGfd4KD5wbKh9JYH34"></drupal-render-placeholder> </div> <!--/.comment-form --> </section> Fri, 23 Oct 2020 07:23:02 +0000 noviceadmin 7 at https://www.novicedev.com