Git 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 a GIT Branch from a Commit? https://www.novicedev.com/blog/create-git-branch-commit <span>How to Create a GIT Branch from a Commit?</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/How%20to%20Create%20a%20GIT%20Branch%20from%20a%20Commit%3F%20.png?itok=SYzPaSG3" width="772" height="432" alt="How to Create a GIT Branch from a Commit?" title="How to Create a GIT Branch from a Commit?" class="image-field" /> </div> <span><span>noviceadmin</span></span> <span>Mon, 09/12/2022 - 11:14</span> <div> <div class="field-item"> <div class="paragraph paragraph--type--text paragraph--view-mode--default"> <div class="field field--name-field-para-text field--type-text-long field--label-hidden field-item"><p>Usually, a branch is created from another branch which is the latest HEAD commit of the branch. But what if you want to create a branch from a previous commit HEAD?</p> <p><strong>GIT branch can be created with a commit hash using the ‘git checkout’ command with ‘-b’ option and then pass a new branch name with the commit SHA.</strong></p> <pre> <code class="language-bash">$ git checkout -b &lt;new-branch&gt; &lt;commit-sha&gt;</code></pre> <p>Or, you can also use the 'git branch' command to <strong>create the branch without switching</strong> to the new branch.</p> <pre> <code class="language-bash">$ git branch &lt;new-branch&gt; &lt;commit-sha&gt;</code></pre> <p> </p> <p>Here are the detailed steps to <strong>create a GIT branch from a commit hash</strong> with the git checkout command:</p> <h2>1. Find commit SHA with git log</h2> <p>The first step is to <strong>find the commit SHA</strong> from which you want to create the branch.</p> <p>Use ‘git log’ command with ‘--online’ and ‘--graph’ options to get the commit SHA.</p> <pre> <code class="language-bash">$ git log --oneline --graph * 39710b8 (HEAD -&gt; feature-2) Feature 2 added. * ecddf76 Feature 1 added. * 34cd5ff (new-branch, develop) Test commit.</code></pre> <p>Now you can see 3 commits in the git history.</p> <h2>2. Create new branch from commit SHA</h2> <p>Now let's assume you want to create a branch from the second commit with commit hash value 'ecddf76'.</p> <pre> <code class="language-bash">$ git checkout -b feature-102 ecddf76</code></pre> <h2>3. Confirm new branch head</h2> <p>Use 'git log' command again to make sure that the <strong>new branch is created from the correct commit SHA</strong></p> <pre> <code class="language-bash">$ git log --oneline --graph * ecddf76 (HEAD -&gt; feature-104) Feature 1 added. * 34cd5ff (new-branch, develop) Test commit.</code></pre> <p> </p> <p>Now you have successfully created a new branch from a commit in the commit history.</p> <p>Further reading: <a href="https://www.atlassian.com/git/tutorials/using-branches/git-checkout">https://www.atlassian.com/git/tutorials/using-branches/git-checkout</a></p> </div> </div> </div> </div> <div class="node-taxonomy-container"> <ul class="taxonomy-terms"> <li class="taxonomy-term"><a href="/topic/git" hreflang="en">Git</a></li> </ul> </div> <!--/.node-taxonomy-container --> <section id="node-article-comment" 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=28&amp;2=comment&amp;3=comment" token="MhJr4jB4OBSufd7SKEhVwPShYGWGG1grOo6UzQp4acs"></drupal-render-placeholder> </div> <!--/.comment-form --> </section> Mon, 12 Sep 2022 11:14:00 +0000 noviceadmin 28 at https://www.novicedev.com How to Create a Git Branch (WITH EXAMPLE) https://www.novicedev.com/blog/how-create-git-branch-example <span>How to Create a Git Branch (WITH EXAMPLE)</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/How%20to%20Create%20a%20Branch%20in%20GIT%3F.png?itok=5IpMD-AV" width="772" height="481" alt="How to Create a Git Branch (WITH EXAMPLE)" title="How to Create a Git Branch (WITH EXAMPLE)" class="image-field" /> </div> <span><span>noviceadmin</span></span> <span>Mon, 09/12/2022 - 03:33</span> <div> <div class="field-item"> <div class="paragraph paragraph--type--text paragraph--view-mode--default"> <div class="field field--name-field-para-text field--type-text-long field--label-hidden field-item"><p>Whenever you start developing a new feature you must start with creating a new branch git. This way you separate your feature changes from other branches.</p> <p><strong>A new branch can be created with the ‘git checkout’ command with the ‘-b’ option and a new branch name as arguments. This will create a new branch from your current branch and also switch the branch to the new branch.</strong></p> <pre> <code class="language-bash">$ git checkout -b &lt;new-branch&gt;</code></pre> <p>But if you don't want to create a new branch from the current branch then you can also pass the base branch as an argument.</p> <pre> <code class="language-bash">$ git checkout -b &lt;new-branch&gt; &lt;base-branch&gt;</code></pre> <p>Once the feature is completed, this new branch can be merged back into the other branch.</p> <h2>Example of creating a GIT branch</h2> <p>Let's take an example, you want to <strong>create a new feature branch</strong> 'feature-2' from the master branch.</p> <h3>1. Checkout master branch (source branch)</h3> <p>First, make sure your current git branch is the master branch. You can check this by running "git branch" or "git branch --show-current" commands</p> <pre> <code class="language-bash">$ git branch feature-1 * master</code></pre> <p>If not, then make sure to checkout the master branch.</p> <pre> <code class="language-bash">$ git checkout master</code></pre> <h3>2. Run the "git checkout" command with "-b" and feature the branch name</h3> <p>Now you can run the GIT checkout command to create a new feature branch "feature-2"</p> <pre> <code class="language-bash">$ git checkout -b feature-2 Switched to a new branch 'feature-2'</code></pre> <p>Once run successfully, the new branch will be created and your current branch will be switched to this new branch.</p> <h3>3. Confirm the new branch</h3> <p>You can verify your new branch by running the ‘git branch’ command.</p> <pre> <code class="language-bash">$ git branch feature-1 * feature-2 master</code></pre> <p> </p> <h2>Conclusion</h2> <p>In this tutorial, we learned to create a new branch in GIT with the "git checkout" command. This can also be achieved with the "git branch" command.</p> <p>A GIT branch is not the only source for creating a new feature branch. A New GIT branch can also be created from <a href="https://www.novicedev.com/blog/create-git-branch-commit">commit SHA</a>, <a href="https://www.novicedev.com/blog/how-create-new-git-branch-tag">a tag</a>, or a remote branch.</p> </div> </div> </div> </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> </ul> </div> <!--/.node-taxonomy-container --> <section id="node-article-comment" 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=26&amp;2=comment&amp;3=comment" token="DlHzb4c3ll6eORQiZAxAlDl2xxGjcquBWx-IdVT-xfk"></drupal-render-placeholder> </div> <!--/.comment-form --> </section> Mon, 12 Sep 2022 03:33:51 +0000 noviceadmin 26 at https://www.novicedev.com GIT STASH: Save uncommitted changes (WITH EXAMPLES) https://www.novicedev.com/blog/git-stash-guide <span>GIT STASH: Save uncommitted changes (WITH EXAMPLES)</span> <span><span>noviceadmin</span></span> <span>Thu, 04/07/2022 - 06:25</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field-item"><p>Want to switch the git branch for some other quick fix but don’t want to commit changes in the current branch then the “git stash” command is here for your rescue.</p> <h2>What is Git stash?</h2> <p><strong>Git stash command is used to store changes that you don’t want to commit now and take you to the last commit of the branch. And later when you are ready you can reapply the stashed changes.</strong></p> <p>Now let's see in more detail with examples of how to use “git stash”.</p> <h2><strong>How to use Git stash command?</strong></h2> <p>The simplest git stash workflow is to stash the changes with the git stash command, work on some other functionality and later apply the stashed changes back to get the modified files.</p> <p>Here is a step-by-step example of how to use git stash.</p> <h3>1. Check uncommitted changes</h3> <p>Run “git status” to check for uncommitted changes which you want to save.</p> <pre> <code class="language-bash">$ git status On branch develop Changes not staged for commit: (use "git add &lt;file&gt;..." to update what will be committed) (use "git restore &lt;file&gt;..." to discard changes in working directory) modified: index.php no changes added to commit (use "git add" and/or "git commit -a")</code></pre> <h3>2. Run "git stash" command</h3> <p>If you find any changes which you don't want to commit and work on something else, then run "git stash". Git stash will store changes and will give you a clean branch.</p> <pre> <code class="language-bash">$ git stash Saved working directory and index state WIP on develop: 34cd5ff Test commit.</code></pre> <h3>3. Work on something else</h3> <p>Now you are free to switch to other branches or work on something else without any modified changes in the working directory.</p> <h3>4. Get a clean working directory</h3> <p>Once you are done with other work you need to make sure you have a clean working directory by running "git status".</p> <pre> <code class="language-bash">$ git status On branch develop nothing to commit, working tree clean</code></pre> <h3>5. Run "git stash pop"</h3> <p>Now run the "git stash pop" command to get back your stashed changes. This command reapplies the last stashed change to the working directory and deletes it from the stash.</p> <pre> <code class="language-bash">$ git stash pop On branch develop Changes not staged for commit: (use "git add &lt;file&gt;..." to update what will be committed) (use "git restore &lt;file&gt;..." to discard changes in working directory) modified: index.php no changes added to commit (use "git add" and/or "git commit -a") Dropped refs/stash@{0} (d75596436aa3c3e926061d2213e3f2959bc2b16b)</code></pre> <h3>6. Check modified changes</h3> <p>You can run git status again to make sure everything is okay and you have your modified changes back.</p> <pre> <code class="language-bash">$ git status On branch develop Changes not staged for commit: (use "git add &lt;file&gt;..." to update what will be committed) (use "git restore &lt;file&gt;..." to discard changes in working directory) modified: index.php no changes added to commit (use "git add" and/or "git commit -a")</code></pre> <h2> </h2> <h2><strong>Advanced Git stash commands</strong></h2> <p>Git stash also comes with many useful <strong>advanced command</strong>s which will help you in specific scenarios.</p> <ul> <li>git stash</li> <li>git stash apply</li> <li>git stash list</li> <li>git stash drop</li> <li>git stash clear</li> <li>git stash pop</li> <li>git stash branch</li> <li>git stash file</li> <li>git stash show</li> </ul> <h2> </h2> <h2><strong>More resources</strong></h2> <ul> <li><a href="https://www.atlassian.com/git/tutorials/saving-changes/git-stash" target="_blank">https://www.atlassian.com/git/tutorials/saving-changes/git-stash</a></li> <li><a href="https://docs.gitlab.com/ee/topics/git/stash.html" target="_blank">https://docs.gitlab.com/ee/topics/git/stash.html</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> </ul> </div> <!--/.node-taxonomy-container --> <section id="node-article-comment" 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=17&amp;2=comment&amp;3=comment" token="B_jr1cz7gicq8lxY4PqWeJI7K26EGwp7nNbZxPjUVjE"></drupal-render-placeholder> </div> <!--/.comment-form --> </section> Thu, 07 Apr 2022 06:25:36 +0000 noviceadmin 17 at https://www.novicedev.com How to Rename GIT Branch? https://www.novicedev.com/blog/rename-git-branch <span>How to Rename GIT Branch?</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/How%20to%20rename%20a%20git%20branch%3F.png?itok=n8UEbGRU" width="772" height="428" alt="How to Rename GIT Branch?" title="How to Rename GIT Branch?" class="image-field" /> </div> <span><span>noviceadmin</span></span> <span>Thu, 01/27/2022 - 16:32</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field-item"><p>Made a small mistake while naming your git branch, don't panic this blog post will go through all the possibilities for renaming the git branch on local and remote.</p> <p><em><strong>Git branch can be renamed with a simple command "git branch -m &lt;new-name&gt;", this will rename your current git branch name. Once the branch is renamed on local you can push the new branch to remote and delete the old git branch on the remote.</strong></em></p> <p>Now let's go through some detail on <strong>why and how to rename a git branch on local and remote</strong>.</p> <h2><strong>Why you might want to rename the git branch name?</strong></h2> <p>Before going into details of how to rename local and remote git branches, let's see the reason why you might want to do it:</p> <ul> <li>You might want to rename your git branch if the <strong>branch name does not match your project branch naming standards</strong>.</li> <li>You might have the wrong branch name or a <strong>wrong ticket number in your branch name</strong>.</li> <li>Sometimes you might make a <strong>typo mistake while naming your branch</strong> and want to make it perfect by renaming it.</li> </ul> <h2><strong>How to rename the local git branch?</strong></h2> <p>Now let's see how to rename a git branch on local with these steps:</p> <ol> <li>The first step to rename a branch is to <strong>checkout the branch</strong> you might want to rename. <pre> <code>$ git checkout &lt;old-name&gt;</code></pre> </li> <li>Now you can <strong>run the "git branch" command with -m</strong> and the new branch name <pre> <code>$ git branch -m &lt;new-name&gt;</code></pre> </li> <li>To check if the branch is renamed correctly you can run the <strong>"git branch" or "git status" command to check your current branch</strong> <pre> <code>$ git branch</code></pre> <pre> <code>$ git status On branch new-name nothing to commit, working tree clean</code></pre> </li> </ol> <p>If your old git branch was only on your local and not pushed to remote then you can stop here.</p> <p>But if you have the wrong branch name on remote as well then continue reading.</p> <h2><strong>How to rename remote git branch?</strong></h2> <p>In the previous stage, we rename the git branch on local and now we will <strong>follow these steps to update the branch name on remote</strong> as well.</p> <ol> <li>Once the branch is renamed on local, run the below command to <strong>push the renamed branch to remote</strong> <pre> <code>$ git push origin -u &lt;new-name&gt;</code></pre> </li> <li>Pushing the branch to remote with the new name will now delete the old branch on the remote. You need to run the below command to <strong>delete the remote branch with the old name</strong>. <pre> <code>$ git push origin --delete &lt;old-name&gt;</code></pre> </li> </ol> <h2><strong>Conclusion</strong></h2> <p>Okay, now we know that there is <strong>no need to panic</strong> if you made a mistake while naming your git branch.</p> <p>We have seen why might need to rename your git branch, how to rename a branch on local, and then how to push it to the remote repository if required.</p> <p>And always <strong>remember to remove the old git branch from the remote</strong> to make sure no one uses it.</p> <p> </p> <p><strong>Leave a comment</strong> if you need to know more about renaming your git branch and do check out our blog post on <strong><a href="https://www.novicedev.com/blog/16-basic-commands-get-started-git">basic git commands you should know</a></strong>.</p> </div> <div class="node-taxonomy-container"> <ul class="taxonomy-terms"> <li class="taxonomy-term"><a href="/topic/git" hreflang="en">Git</a></li> </ul> </div> <!--/.node-taxonomy-container --> <section id="node-article-comment" 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=20&amp;2=comment&amp;3=comment" token="jtHSIrb3ssKST-mcOv2EwGPqTrf6EHDsSXb8MjW_QiI"></drupal-render-placeholder> </div> <!--/.comment-form --> </section> Thu, 27 Jan 2022 16:32:49 +0000 noviceadmin 20 at https://www.novicedev.com 16 Basic Git Commands with EXAMPLES https://www.novicedev.com/blog/16-basic-git-commands-examples <span>16 Basic Git Commands with EXAMPLES</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-01/16-basic-git-commands.png?itok=TNKEIw-W" width="772" height="434" alt="16 Basic Git Commands with EXAMPLES" title="16 Basic Git Commands with EXAMPLES" class="image-field" /> </div> <span><span>noviceadmin</span></span> <span>Mon, 01/03/2022 - 14:35</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field-item"><p>As a beginner knowing all the git commands could be overwhelming, but you can get away with some basic git commands at the start.</p> <p>In this article, we will go through these 16 basic git commands that you should know as a new developer.</p> <ol> <li>git clone</li> <li>git init</li> <li>git checkout</li> <li>git branch</li> <li>git config</li> <li>git status</li> <li>git diff</li> <li>git add</li> <li>git commit</li> <li>git push</li> <li>git remote</li> <li>git pull</li> <li>git log</li> <li>git rm</li> <li>git stash</li> <li>git fetch</li> </ol> <p>Now let's go through them in little detail...</p> <h2><strong>1. Git clone</strong></h2> <p>Git clone git command is used when you are trying to <strong>download a project from a remote repository</strong>.</p> <p><strong>Syntax:</strong></p> <pre> <code class="language-bash">$ git clone &lt;repository&gt;</code></pre> <p><strong>Example:</strong></p> <pre> <code class="language-bash">$ git clone https://github.com/git/git.git</code></pre> <p> </p> <h2><strong>2. Git init</strong></h2> <p>Git init command is used to <strong>convert a directory into a git repository</strong>. This command is useful when you are starting a new project or want to initialize git in an existing project.</p> <p><strong>Syntax:</strong></p> <pre> <code class="language-bash">$ git init</code></pre> <p> </p> <h2><strong>3. Git checkout</strong></h2> <p>Git checkout command is used to <strong>switch your current branch to another one</strong>.</p> <p><strong>Syntax:</strong></p> <pre> <code class="language-bash">$ git checkout &lt;branch_name&gt;</code></pre> <p>With -b option Git checkout branch can also create a new branch from the current branch.</p> <p><strong>Syntax:</strong></p> <pre> <code class="language-bash">$ git checkout -b &lt;new_branch&gt;</code></pre> <p> </p> <h2><strong>4. Git branch</strong></h2> <p>Git branch command is used to <strong>list all the branches</strong> on your local repository. And the output will highlight the current branch you are in.</p> <p><strong>Syntax:</strong></p> <pre> <code class="language-bash">$ git branch</code></pre> <p>Git branch command can also be used to <strong>create a new branch</strong> by adding the name of the new branch at end of the command.</p> <p><strong>Syntax:</strong></p> <pre> <code class="language-bash">$ git branch &lt;new_branch&gt;</code></pre> <p> </p> <h2><strong>5. Git config</strong></h2> <p>Git config command is used to <strong>set the git user config</strong> for the project or globally. At the start of your project make sure you set the correct user.name and user.email for your project.</p> <p><strong>Syntax:</strong></p> <pre> <code class="language-bash">$ git config &lt;setting&gt; &lt;command&gt;</code></pre> <p><strong>Example:</strong></p> <pre> <code class="language-bash">git config user.email [email protected] git config user.name “John Corner”</code></pre> <p>Git config command can also be used to set this config globally. You can find more information about the git config command <a href="https://www.atlassian.com/git/tutorials/setting-up-a-repository/git-config">here</a>.</p> <p> </p> <h2><strong>6. Git status</strong></h2> <p>Git status command <strong>returns the current status</strong> of your working directory. This is the best way to know what is modified, added or deleted in your repository.</p> <p><strong>Syntax:</strong></p> <pre> <code class="language-bash">$ git status</code></pre> <p> </p> <h2><strong>7. Git diff</strong></h2> <p>Git diff command can be used in many different ways and initially, you can use it to <strong>check what is modified in a file or directory</strong>.</p> <pre> <code class="language-bash">$ git diff &lt;file_name or directory_name&gt;</code></pre> <p> </p> <h2><strong>8. Git add</strong></h2> <p>Git add command is used to <strong>move new or modified files to the staging area</strong>. After this changes can be committed.</p> <p><strong>Syntax:</strong></p> <pre> <code class="language-bash">$ git add &lt;file_name or directory_name&gt;</code></pre> <p>If you want to add all files then use the git add command with “.”.</p> <p><strong>Syntax:</strong></p> <pre> <code class="language-bash">$ git add .</code></pre> <p> </p> <h2><strong>9. Git commit</strong></h2> <p>Once you are done with your changes, the <strong>git commit command is used to save your change</strong> in the git branch.</p> <p><strong>Syntax:</strong></p> <pre> <code class="language-bash">$ git commit -m “Your commit message.”</code></pre> <p> </p> <h2><strong>10. Git push</strong></h2> <p>To more your local committed changes to remote use git push command. With this command, you <strong>push your local branch to the remote repository</strong>.</p> <p><strong>Syntax:</strong></p> <pre> <code class="language-bash">$ git push &lt;remote&gt; &lt;branch&gt;</code></pre> <p> </p> <h2><strong>11. Git remote</strong></h2> <p>Git remote command with different options helps to sync the local repository with the remote repository. You can view, create/add, delete, rename remote to other repositories.</p> <p>Git remote command is used to <strong>show the remote repository name and URL</strong> to which your local repository is connected.</p> <p><strong>Syntax:</strong></p> <pre> <code class="language-bash"># View remote $ git remote -v # Add remote $ git remote add &lt;remote_name&gt; &lt;remote_path&gt; # Delete remote $ git remote rm &lt;remote_name&gt; # Rename remote $ git remote rename &lt;old_remote_name&gt; &lt;new_remote_name&gt;</code></pre> <p> </p> <h2><strong>12. Git pull</strong></h2> <p>As the name suggests, the <strong>git pull command will fetch all the changes</strong> from the remote repository and merge them into your local repository.</p> <pre> <code class="language-bash">$ git pull</code></pre> <p> </p> <h2><strong>13. Git log</strong></h2> <p>Git log command is used to <strong>show commit history in the current branch</strong> on your local repository. Commit history will be in chronological order with unique commit hash, commit author and date.</p> <pre> <code class="language-bash">$ git log</code></pre> <p>You can use the git log command with other options to filter the logs.</p> <p> </p> <h2><strong>14. Git rm</strong></h2> <p>Git rm command is used to <strong>remove files or directories</strong> from the git index. Different options can be used with the git rm command to get the desired result.</p> <p>And keep in mind the git rm command will also remove files from the working directory.</p> <p><strong>Syntax:</strong></p> <pre> <code class="language-bash">$ git rm &lt;file_name&gt;</code></pre> <p> </p> <h2><strong>15. Git stash</strong></h2> <p><a href="/blog/save-changes-temporarily-git-stash">Git stash</a> command is used to <strong>save current changes</strong> of modified files and get a clean branch.</p> <p>You will need git stash when you want to move to a different branch but can't because you have modified changes in your current branch.</p> <pre> <code class="language-bash">$ git stash</code></pre> <p>You can always come back to your original branch and do the <strong>"git stash pop" command to get back your stashed changes</strong>.</p> <p> </p> <h2><strong>16. Git fetch</strong></h2> <p>Git fetch is used when you want to <strong>get updates from a remote repository</strong>.</p> <p>It works the same as git pull doesn't merge the changes into your local repository.</p> <p><strong>Syntax:</strong></p> <pre> <code class="language-bash">$ git fetch &lt;remote_name&gt;</code></pre> <p> </p> <h3><strong>Conclusion</strong></h3> <p>These are only the <strong>basic git command that every beginner</strong> should start with. All these git commands can be used in many different ways by adding arguments with them.</p> <p>And you can always test these git commands and get familiar with them by creating a free git repository on <a href="https://github.com/">Github</a> or <a href="https://gitlab.com/users/sign_in">Gitlab</a>.</p> </div> <div class="node-taxonomy-container"> <ul class="taxonomy-terms"> <li class="taxonomy-term"><a href="/topic/git" hreflang="en">Git</a></li> </ul> </div> <!--/.node-taxonomy-container --> <section id="node-article-comment" 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=22&amp;2=comment&amp;3=comment" token="8G-0ziIYgIKVNZP_lsiweU7U_jtelpkeubzWPKGyBMY"></drupal-render-placeholder> </div> <!--/.comment-form --> </section> Mon, 03 Jan 2022 14:35:41 +0000 noviceadmin 22 at https://www.novicedev.com How To Clone A GIT Repository https://www.novicedev.com/blog/how-clone-git-repository <span>How To Clone A GIT Repository</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-01/git-clone.png?itok=vUAUrJ4n" width="772" height="456" alt="How To Clone A GIT Repository" title="How To Clone A GIT Repository" class="image-field" /> </div> <span><span>noviceadmin</span></span> <span>Sat, 12/25/2021 - 15:47</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field-item"><p>Git clone command is used when you are trying to download a project from an existing remote repository. Once the git clone command is successfully executed you will have a copy of the repo in your machine.</p> <p><strong>Git repository can be downloaded or cloned with the "git clone" command with the path of the repository as an argument. This will clone the specified git repository folder in your current directory. A repository can also be cloned in a specific folder using the directory argument after the repository path.</strong></p> <p>Now let's see in more detail with examples on how to clone or download a git repository.</p> <h2>Clone Git repository</h2> <p>The below command will <strong>clone the remote git repository</strong> and the name of the directory will be the same as the repository name.</p> <p><strong>Syntax:</strong></p> <pre> <code class="language-bash">$ git clone &lt;repository&gt;</code></pre> <p><strong>Example:</strong></p> <pre> <code class="language-bash">$ git clone https://github.com/username/myproject.git</code></pre> <h2>Git clone to the specific directory</h2> <p>With the git clone command, you can <strong>add a directory name in front of the repository option</strong> to clone the repository in a particular directory.</p> <p><strong>Syntax:</strong></p> <pre> <code class="language-bash">$ git clone &lt;repository&gt; &lt;directory&gt;</code></pre> <p><strong>Example:</strong></p> <pre> <code class="language-bash">$ git clone https://github.com/username/myproject.git my_project</code></pre> <h2>Conclusion</h2> <p>Now we know how simple it is to get started with <strong>getting code from a remote repository to your local machine</strong> with the Git Clone command. And make sure to go into the cloned directory to start working with the project.</p> <p>If you need to explore more about the Git clone command or different configuration options available with the head to <a href="https://www.atlassian.com/git/tutorials/setting-up-a-repository/git-clone">this document</a>.</p> </div> <div class="node-taxonomy-container"> <ul class="taxonomy-terms"> <li class="taxonomy-term"><a href="/topic/git" hreflang="en">Git</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=21&amp;2=comment&amp;3=comment" token="5XSG_rpahIxFRK6x2zFQ269KDIgAOiq-4yaA65G5Kkc"></drupal-render-placeholder> </div> <!--/.comment-form --> </section> Sat, 25 Dec 2021 15:47:28 +0000 noviceadmin 21 at https://www.novicedev.com How to checkout a git tag https://www.novicedev.com/blog/how-checkout-git-tag <span>How to checkout a git 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/2021-12/How%20to%20checkout%20a%20git%20tag.png?itok=5RioucGj" width="772" height="434" alt="How to checkout a git tag" title="How to checkout a git tag" class="image-field" /> </div> <span><span>noviceadmin</span></span> <span>Sun, 08/29/2021 - 15:23</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field-item"><p><meta charset="utf-8" /></p> <p>Git <a href="/blog/how-create-git-tags-examples">tags are created</a> to mark a release candidate. Because it points directly to a commit in the git history and will not change.</p> <p>But sometimes we need to checkout a remote tag to our local. You can achieve this by fetching it from remote and checkout it as a branch on local.</p> <p>Here is how we can achieve this.</p> <h2>Fetch git tags</h2> <p>The first thing you need is to fetch the git tag to your local. You can do this by using the git fetch command with --all and --tags arguments.</p> <pre> <code>$ git fetch --all --tags</code></pre> <h2><br /> Checkout tag as a branch</h2> <p>The next step is to checkout a specific tag as a branch with git checkout command with the tag name and new branch name.</p> <pre> <code>$ git checkout tags/&lt;tag_name&gt; -b &lt;branch_name&gt;</code></pre> <p>Now you can test the code from a tag on your local branch and make updates as well.</p> </div> <div class="node-taxonomy-container"> <ul class="taxonomy-terms"> <li class="taxonomy-term"><a href="/topic/git" hreflang="en">Git</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=13&amp;2=comment&amp;3=comment" token="IpQiXavlekgUkoMY55I96KcK_vUoClR5uCQ4Y4laa90"></drupal-render-placeholder> </div> <!--/.comment-form --> </section> Sun, 29 Aug 2021 15:23:47 +0000 noviceadmin 13 at https://www.novicedev.com How to delete local and remote git tags (WITH EXAMPLES) https://www.novicedev.com/blog/how-delete-git-tag-local-and-remote-examples <span>How to delete local and remote git tags (WITH EXAMPLES)</span> <span><span>noviceadmin</span></span> <span>Tue, 10/27/2020 - 06:05</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field-item"><p>Once you have <a href="https://www.novicedev.com/blog/how-create-git-tags-examples">created a git tag</a>, you might realize that the git tag name is wrong and does not match the release pattern. In this scenario, you might want to delete the git tag.</p> <p>It might be possible you have already pushed the wrong git tag to the remote. So in this tutorial, we will see how to delete a git tag from local as well as from remote.</p> <h2>How to delete local git tag</h2> <p>To <strong>delete a local git tag</strong> simply run the "git tag" command with the -d option and tag name. To know the tag name you can run the "git tag" command with the -l option to list all tags, identify the tag you want to delete.</p> <p>Here is an example of how to delete a local tag in git.</p> <pre> <code class="language-bash">$ git tag -l v1.0 v2.0 v2.5 v3.0 $ git tag -d v2.5 Deleted tag 'v2.5' (was aea93f1727) $ git tag -l v1.0 v2.0 v3.0</code></pre> <p>You can run the "git tag" with the -l option to verify that the tag is deleted.</p> <h2>How to delete remote git tag</h2> <p>There are two ways to delete the remote git tag.</p> <p>One is to delete the tag from local first (as shown above) and then push it to the remote. Another option is to delete the tag from the remote.</p> <p>Let check both methods of deleting a tag from remote.</p> <p>Once the tag is removed from local, the next step would be <strong>to remove the remote git tag</strong> using the command below.</p> <pre> <code class="language-bash">$ git push origin :refs/tags/v2.5 To [email protected]:username/project.git - [deleted] v2.5</code></pre> <p>For <strong>directly deleting the remote git tag</strong>, use the "git push origin" command with --delete option and tag name.</p> <pre> <code class="language-bash">$ git push origin --delete v2.5 To [email protected]:username/project.git - [deleted] v2.5</code></pre> <h2>Recap</h2> <p>So in this blog post, we learned about how to <strong>delete the local git tag and then push that deletion to the remote</strong>. And another option is to directly delete the remote git tag.</p> <p> </p> <p>You can read further about git tags in the following articles:</p> <ul> <li> <p><a href="https://www.novicedev.com/blog/how-create-git-tags-examples">How to create git tags (With examples)</a></p> </li> <li> <p><a href="https://www.novicedev.com/blog/how-push-git-tag-remote-example">How to push git tag to remote (With example)</a></p> </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> </ul> </div> <!--/.node-taxonomy-container --> <section id="node-article-comment--3" 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=6&amp;2=comment&amp;3=comment" token="7H2NushWfAU6Qys0xeMiKDyrLvbqw6kb1N4k7BFyk50"></drupal-render-placeholder> </div> <!--/.comment-form --> </section> Tue, 27 Oct 2020 06:05:19 +0000 noviceadmin 6 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