<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>git &amp;mdash; sandeepk</title>
    <link>https://blogs.dgplug.org/sandeepk/tag:git</link>
    <description></description>
    <pubDate>Thu, 30 Apr 2026 21:27:59 +0000</pubDate>
    <item>
      <title>Git Worktree</title>
      <link>https://blogs.dgplug.org/sandeepk/git-worktree</link>
      <description>&lt;![CDATA[A few days ago, during our office knowledge-sharing meeting, someone introduced the git worktree command. It lets you create a new branch parallel to your current working branch so you can start something new — or handle a hotfix — without stashing or committing your unfinished changes.&#xA;&#xA;It turned out to be incredibly useful. With git worktree, you can maintain multiple working directories linked to the same Git repository with almost no friction.&#xA;&#xA;---&#xA;&#xA;Why use worktrees?&#xA;&#xA;Imagine you&#39;re working on a long-running feature — say, an optimization — and suddenly you’re assigned an urgent production bug.&#xA;Typically, you would stash your changes or make a temporary commit, switch branches, fix the bug, then restore everything. It&#39;s annoying and error-prone.&#xA;&#xA;With worktrees, you can directly spin up a parallel working directory:&#xA;&#xA;git worktree add path&#xA;Example:&#xA;git worktree add ../hotfix&#xA;&#xA;This creates a new linked worktree, associated with your current repository, with its own metadata and branch checkout. Your original work remains untouched.&#xA;&#xA;---&#xA;&#xA;Removing a worktree&#xA;&#xA;Once you&#39;re done with the hotfix (or any task), removing the worktree is just as simple:&#xA;&#xA;git worktree remove path&#xA;&#xA;If you delete the directory manually, Git will eventually clean up its administrative files automatically (based on gc.worktreePruneExpire in git-config).&#xA;You can also remove stale entries explicitly:&#xA;&#xA;git worktree prune&#xA;&#xA;---&#xA;&#xA;Other useful worktree commands&#xA;&#xA;1. Create a throwaway worktree (detached HEAD)&#xA;&#xA;Perfect for quick experiments:&#xA;&#xA;git worktree add -d path&#xA;&#xA;2. Create a worktree for an existing branch&#xA;&#xA;git worktree add path branch&#xA;&#xA;This checks out the given branch into a new, isolated working directory.&#xA;&#xA;---&#xA;&#xA;Further reading&#xA;&#xA;To dive deeper into git worktree:&#xA;&#xA;Official docs: https://git-scm.com/docs/git-worktree&#xA;Or simply run:&#xA;&#xA;    git help worktree&#xA;  &#xA;&#xA;Cheers!&#xA;&#xA;#Git #TIL #Worktree]]&gt;</description>
      <content:encoded><![CDATA[<p>A few days ago, during our office knowledge-sharing meeting, someone introduced the <code>git worktree</code> command. It lets you create a new branch <em>parallel</em> to your current working branch so you can start something new — or handle a hotfix — <strong>without stashing or committing your unfinished changes</strong>.</p>

<p>It turned out to be incredibly useful. With <code>git worktree</code>, you can maintain multiple working directories linked to the same Git repository with almost no friction.</p>

<hr>

<h2 id="why-use-worktrees">Why use worktrees?</h2>

<p>Imagine you&#39;re working on a long-running feature — say, an optimization — and suddenly you’re assigned an urgent production bug.
Typically, you would stash your changes or make a temporary commit, switch branches, fix the bug, then restore everything. It&#39;s annoying and error-prone.</p>

<p>With worktrees, you can directly spin up a parallel working directory:</p>

<pre><code class="language-bash">git worktree add &lt;path&gt;
# Example:
git worktree add ../hotfix
</code></pre>

<p>This creates a <strong>new linked worktree</strong>, associated with your current repository, with its own metadata and branch checkout. Your original work remains untouched.</p>

<hr>

<h2 id="removing-a-worktree">Removing a worktree</h2>

<p>Once you&#39;re done with the hotfix (or any task), removing the worktree is just as simple:</p>

<pre><code class="language-bash">git worktree remove &lt;path&gt;
</code></pre>

<p>If you delete the directory manually, Git will eventually clean up its administrative files automatically (based on <code>gc.worktreePruneExpire</code> in <code>git-config</code>).
You can also remove stale entries explicitly:</p>

<pre><code class="language-bash">git worktree prune
</code></pre>

<hr>

<h2 id="other-useful-worktree-commands">Other useful worktree commands</h2>

<h3 id="1-create-a-throwaway-worktree-detached-head">1. Create a throwaway worktree (detached HEAD)</h3>

<p>Perfect for quick experiments:</p>

<pre><code class="language-bash">git worktree add -d &lt;path&gt;
</code></pre>

<h3 id="2-create-a-worktree-for-an-existing-branch">2. Create a worktree for an existing branch</h3>

<pre><code class="language-bash">git worktree add &lt;path&gt; &lt;branch&gt;
</code></pre>

<p>This checks out the given branch into a new, isolated working directory.</p>

<hr>

<h2 id="further-reading">Further reading</h2>

<p>To dive deeper into <code>git worktree</code>:</p>
<ul><li>Official docs: <a href="https://git-scm.com/docs/git-worktree" rel="nofollow">https://git-scm.com/docs/git-worktree</a></li>
<li>Or simply run:</li></ul>

<pre><code class="language-bash">  git help worktree
</code></pre>

<p>Cheers!</p>

<p><a href="/sandeepk/tag:Git" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">Git</span></a> <a href="/sandeepk/tag:TIL" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">TIL</span></a> <a href="/sandeepk/tag:Worktree" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">Worktree</span></a></p>
]]></content:encoded>
      <guid>https://blogs.dgplug.org/sandeepk/git-worktree</guid>
      <pubDate>Sun, 30 Nov 2025 13:27:11 +0000</pubDate>
    </item>
    <item>
      <title>No newline at the end of file ¯\(ツ)/¯</title>
      <link>https://blogs.dgplug.org/sandeepk/no-newline-at-the-end-of-file-_-tsu-_</link>
      <description>&lt;![CDATA[I came to see this warning a few days back when I was seeing the git diff of a file in reaction to this I open the file and hit enter at the last line to my surprise the warning remains still the same.&#xA;&#xA;What is a new line?&#xA;The new line is usually \n, aka (CR or CRLF) at the end of the file. It&#39;s helpful to identify the last byte of the file.&#xA;&#xA;Why it is good to have a new line at the end of the file?&#xA;&#xA;Quoting from here&#xA;&#xA;  A source file that is not empty shall end in a new-line character, which shall not be immediately preceded by a backslash character.&#xA;Since this is a &#34;shall&#34; clause, we must emit a diagnostic message for a violation of this rule.&#xA;&#xA;So, it turns out that, according to POSIX, every text file should end with a \n, or “newline” (not “a new line”) character. This acts as the eol, or the “end of line” character. It is a line “terminator”.&#xA;&#xA;It&#39;s helpful to identify the end of file. &#xA;&#xA;How to automatically add one with your favorite editor?&#xA;&#xA;In your favorite editor, you can add newline automatically like this.&#xA;&#xA;Emacs : Add (setq require-final-newline t) to your .emacs or .emacs.d/init.el file.&#xA;VS Code:  set &#34;files.insertFinalNewline&#34;: true&#xA;&#xA;#100DaysToOffload #POSIX #Git #NoNewLine&#xA;&#xA;]]&gt;</description>
      <content:encoded><![CDATA[<p>I came to see this warning a few days back when I was seeing the git diff of a file in reaction to this I open the file and hit enter at the last line to my surprise the warning remains still the same.</p>

<p><strong>What is a new line?</strong>
The new line is usually <em>\n</em>, aka (CR or CRLF) at the end of the file. It&#39;s helpful to identify the last byte of the file.</p>

<p><strong>Why it is good to have a new line at the end of the file?</strong></p>

<p>Quoting from <a href="https://gcc.gnu.org/legacy-ml/gcc/2003-11/msg01568.html" rel="nofollow">here</a></p>

<blockquote><p>A source file that is not empty shall end in a new-line character, which shall not be immediately preceded by a backslash character.
Since this is a “shall” clause, we must emit a diagnostic message for a violation of this rule.</p></blockquote>

<p>So, it turns out that, according to POSIX, every text file should end with a \n, or “newline” (not “a new line”) character. This acts as the <em>eol</em>, or the “end of line” character. It is a line “terminator”.</p>

<p>It&#39;s helpful to identify the end of file.</p>

<p><strong>How to automatically add one with your favorite editor?</strong></p>

<p>In your favorite editor, you can add newline automatically like this.</p>
<ul><li><strong>Emacs</strong> : Add (setq require-final-newline t) to your .emacs or .emacs.d/init.el file.</li>
<li><strong>VS Code</strong>:  set “files.insertFinalNewline”: true</li></ul>

<p><a href="/sandeepk/tag:100DaysToOffload" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">100DaysToOffload</span></a> <a href="/sandeepk/tag:POSIX" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">POSIX</span></a> <a href="/sandeepk/tag:Git" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">Git</span></a> <a href="/sandeepk/tag:NoNewLine" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">NoNewLine</span></a></p>
]]></content:encoded>
      <guid>https://blogs.dgplug.org/sandeepk/no-newline-at-the-end-of-file-_-tsu-_</guid>
      <pubDate>Sun, 16 May 2021 13:52:00 +0000</pubDate>
    </item>
    <item>
      <title>Git: Commands</title>
      <link>https://blogs.dgplug.org/sandeepk/git-commands</link>
      <description>&lt;![CDATA[Git is a version control tool, that helps to track changes in the project. We will discuss a few useful commands which are handy to know while working with the git&#xA;&#xA;Creating a branch with no commits on it&#xA;      git checkout --orphan branchname&#xA;      git log&#xA;fatal: your current branch &#39;branchname&#39; does not have any commits yet&#xA;&#xA;Remove stale branches&#xA;In your local, if you have branches that are removed in the remote then you can use the       git remote prune origin&#xA;&#xA;To pick a commit from another branch&#xA;If you want to pick a commit from other branches into your current branch you can use the       git cherry-pick -x commit SHA1&#xA;&#xA;To view commits that are not pushed yet&#xA;      git log @{u}..&#xA;&#xA;Run previous command&#xA;In Git, we are also switching from one branch to the other. Typing the name, again and again, is tedious. You can use       randomos git:(uselessdict) git checkout addnumbers&#xA;Switched to branch &#39;addnumbers&#39;&#xA;Your branch is up-to-date with &#39;origin/addnumbers&#39;.&#xA;      randomos git:(addnumbers) git checkout -&#xA;Switched to branch &#39;uselessdict&#39;&#xA;Your branch is up-to-date with &#39;origin/useless_dict&#39;.&#xA;&#xA;If you have any Git commands which you feel are worth sharing and can save some time. Please do share.&#xA;&#xA;Cheers!&#xA;&#xA;#100DaysToOffload  #Git #VersionControl&#xA;&#xA; ]]&gt;</description>
      <content:encoded><![CDATA[<p>Git is a version control tool, that helps to track changes in the project. We will discuss a few useful commands which are handy to know while working with the git</p>

<p><strong>Creating a branch with no commits on it</strong></p>

<pre><code class="language-bash">&gt;&gt;&gt; git checkout --orphan &lt;branch_name&gt;
&gt;&gt;&gt; git log
fatal: your current branch &#39;&lt;branch_name&gt;&#39; does not have any commits yet

</code></pre>

<p><strong>Remove stale branches</strong>
In your local, if you have branches that are removed in the remote then you can use the <code>prune</code> command to delete those branches in local also.</p>

<pre><code class="language-bash">&gt;&gt;&gt; git remote prune origin

</code></pre>

<p><strong>To pick a commit from another branch</strong>
If you want to pick a commit from other branches into your current branch you can use the <code>cherry-pick</code> command and <code>-x</code> for when recording the commit, append a line that says “(cherry picked from commit ...)” to the original commit message to indicate which commit this change was cherry-picked from.</p>

<pre><code class="language-bash">&gt;&gt;&gt; git cherry-pick -x &lt;commit SHA1&gt;

</code></pre>

<p><strong>To view commits that are not pushed yet</strong></p>

<pre><code class="language-bash">&gt;&gt;&gt; git log @{u}..

</code></pre>

<p><strong>Run previous command</strong>
In Git, we are also switching from one branch to the other. Typing the name, again and again, is tedious. You can use <code>-</code> with the Git command, to save your self from typing the name again</p>

<pre><code class="language-bash">&gt;&gt;&gt;  randomos git:(useless_dict) git checkout add_numbers
Switched to branch &#39;add_numbers&#39;
Your branch is up-to-date with &#39;origin/add_numbers&#39;.
&gt;&gt;&gt;  randomos git:(add_numbers) git checkout -
Switched to branch &#39;useless_dict&#39;
Your branch is up-to-date with &#39;origin/useless_dict&#39;.

</code></pre>

<p>If you have any Git commands which you feel are worth sharing and can save some time. Please do share.</p>

<p>Cheers!</p>

<p><a href="/sandeepk/tag:100DaysToOffload" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">100DaysToOffload</span></a>  <a href="/sandeepk/tag:Git" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">Git</span></a> <a href="/sandeepk/tag:VersionControl" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">VersionControl</span></a></p>
]]></content:encoded>
      <guid>https://blogs.dgplug.org/sandeepk/git-commands</guid>
      <pubDate>Wed, 21 Apr 2021 03:06:58 +0000</pubDate>
    </item>
    <item>
      <title>Git: Rebase</title>
      <link>https://blogs.dgplug.org/sandeepk/git-rebase</link>
      <description>&lt;![CDATA[Git rebase is a very handy command to integrate changes from one branch to another, we can run git rebase in two modes manual and interactive. In manual all commit take from the current branch and applied over the head of the passed branch, but in case of the interactive rebase command you have more control over the option to what do with commits.&#xA;&#xA;So to understand how rebase work, we take an example where we have a master branch with the following commits.&#xA;&#xA;      git log&#xA;commit 8bfb8c19c3d7b795e9698a9818880d89ca3c214a&#xA;Author: Sandeep sandeepchoudhary1507@gmail.com&#xA;Date:   Sun Jun 14 01:06:07 2020 +0530&#xA;&#xA;    New goals added&#xA;from this master branch, we create a new branch dev and do some changes/bug fixes.&#xA;&#xA;      git checkout -b dev master&#xA;...&#xA;      git log&#xA;commit a05b6cd75e604df0f4434a574809a4fc14e4313e&#xA;Author: Sandeep sandeepchoudhary1507@gmail.com&#xA;Date:   Sun Jun 14 01:08:11 2020 +0530&#xA;&#xA;    workaround bugs&#xA;&#xA;commit 8bfb8c19c3d7b795e9698a9818880d89ca3c214a&#xA;Author: Sandeep sandeepchoudhary1507@gmail.com&#xA;Date:   Sun Jun 14 01:06:07 2020 +0530&#xA;&#xA;    New goals added&#xA;but in between the other developer push changes in the master branch and to integrate that changes in your current branch you can use merge or rebase command, the rebase helps you maintain the liner history of your workflow.&#xA;      git checkout master&#xA;      git log&#xA;commit 3c5d6baf13aeac37d9efb1218bbf3240ec5c2a12&#xA;Author: Sandeep sandeepchoudhary1507@gmail.com&#xA;Date:   Sun Jun 14 01:07:29 2020 +0530&#xA;&#xA;    new release added&#xA;&#xA;commit 8bfb8c19c3d7b795e9698a9818880d89ca3c214a&#xA;Author: Sandeep sandeepchoudhary1507@gmail.com&#xA;Date:   Sun Jun 14 01:06:07 2020 +0530&#xA;&#xA;    New goals added&#xA;&#xA;so now to integrate new changes from master to your branch dev, without making the commit history complex, we can use rebase command, let&#39;s check out&#xA;      git checkout dev&#xA;      git rebase master&#xA;      git log&#xA;commit 184805896dd5684fc076b9bb9aa34eb3994251b1&#xA;Author: Sandeep sandeepchoudhary1507@gmail.com&#xA;Date:   Sun Jun 14 01:08:11 2020 +0530&#xA;&#xA;    workaround bugs&#xA;&#xA;commit 3c5d6baf13aeac37d9efb1218bbf3240ec5c2a12&#xA;Author: Sandeep sandeepchoudhary1507@gmail.com&#xA;Date:   Sun Jun 14 01:07:29 2020 +0530&#xA;&#xA;    new release added&#xA;&#xA;commit 8bfb8c19c3d7b795e9698a9818880d89ca3c214a&#xA;Author: Sandeep sandeepchoudhary1507@gmail.com&#xA;Date:   Sun Jun 14 01:06:07 2020 +0530&#xA;&#xA;    New goals added&#xA;&#xA;we can also run the rebase command in --interactive mode which gives us the option to edit/squash/... the commits&#xA;      git rebase -i master&#xA;pick 1848058 work around bugs&#xA;&#xA;Rebase 3c5d6ba..1848058 onto 3c5d6ba (1 command(s))&#xA;&#xA;Commands:&#xA;p, pick = use commit&#xA;r, reword = use commit, but edit the commit message&#xA;e, edit = use commit, but stop for amending&#xA;s, squash = use commit, but meld into previous commit&#xA;f, fixup = like &#34;squash&#34;, but discard this commit&#39;s log message&#xA;x, exec = run command (the rest of the line) using shell&#xA;d, drop = remove commit&#xA;&#xA;These lines can be re-ordered; they are executed from top to bottom.&#xA;&#xA;If you remove a line here THAT COMMIT WILL BE LOST.&#xA;&#xA;However, if you remove everything, the rebase will be aborted.&#xA;&#xA;Note that empty commits are commented out&#xA;&#xA;One of the cool use of the git rebase command is that you can change the base of the branch from one branch to other by use of &#xA;--onto option.&#xA;&#xA;Let assume you create a branch featureA from master and then another branch featureB from featureA, to change the base of the featureB branch. &#xA;git rebase --onto newbase oldbase&#xA;      git rebase --onto master featureA featureB&#xA;So this is all about the git rebase command, which can help you to keep your commit history clean and your current working branch commits sync with the master branch.&#xA;&#xA;git]]&gt;</description>
      <content:encoded><![CDATA[<p>Git <strong>rebase</strong> is a very handy command to integrate changes from one branch to another, we can run git rebase in two modes <em>manual</em> and <em>interactive</em>. In manual all commit take from the current branch and applied over the head of the passed branch, but in case of the interactive rebase command you have more control over the option to what do with commits.</p>

<p>So to understand how <strong>rebase</strong> work, we take an example where we have a master branch with the following commits.</p>

<pre><code class="language-bash">&gt;&gt;&gt; git log
commit 8bfb8c19c3d7b795e9698a9818880d89ca3c214a
Author: Sandeep &lt;sandeepchoudhary1507@gmail.com&gt;
Date:   Sun Jun 14 01:06:07 2020 +0530

    New goals added
</code></pre>

<p>from this master branch, we create a new branch <em>dev</em> and do some changes/bug fixes.</p>

<pre><code class="language-bash">&gt;&gt;&gt; git checkout -b dev master
...
&gt;&gt;&gt; git log
commit a05b6cd75e604df0f4434a574809a4fc14e4313e
Author: Sandeep &lt;sandeepchoudhary1507@gmail.com&gt;
Date:   Sun Jun 14 01:08:11 2020 +0530

    workaround bugs

commit 8bfb8c19c3d7b795e9698a9818880d89ca3c214a
Author: Sandeep &lt;sandeepchoudhary1507@gmail.com&gt;
Date:   Sun Jun 14 01:06:07 2020 +0530

    New goals added
</code></pre>

<p>but in between the other developer push changes in the <em>master</em> branch and to integrate that changes in your current branch you can use <em>merge</em> or <em>rebase</em> command, the rebase helps you maintain the liner history of your workflow.</p>

<pre><code class="language-bash">&gt;&gt;&gt; git checkout master
&gt;&gt;&gt; git log
commit 3c5d6baf13aeac37d9efb1218bbf3240ec5c2a12
Author: Sandeep &lt;sandeepchoudhary1507@gmail.com&gt;
Date:   Sun Jun 14 01:07:29 2020 +0530

    new release added

commit 8bfb8c19c3d7b795e9698a9818880d89ca3c214a
Author: Sandeep &lt;sandeepchoudhary1507@gmail.com&gt;
Date:   Sun Jun 14 01:06:07 2020 +0530

    New goals added

</code></pre>

<p>so now to integrate new changes from <em>master</em> to your branch <em>dev</em>, without making the commit history complex, we can use rebase command, let&#39;s check out</p>

<pre><code class="language-bash">&gt;&gt;&gt; git checkout dev
&gt;&gt;&gt; git rebase master
&gt;&gt;&gt; git log
commit 184805896dd5684fc076b9bb9aa34eb3994251b1
Author: Sandeep &lt;sandeepchoudhary1507@gmail.com&gt;
Date:   Sun Jun 14 01:08:11 2020 +0530

    workaround bugs

commit 3c5d6baf13aeac37d9efb1218bbf3240ec5c2a12
Author: Sandeep &lt;sandeepchoudhary1507@gmail.com&gt;
Date:   Sun Jun 14 01:07:29 2020 +0530

    new release added

commit 8bfb8c19c3d7b795e9698a9818880d89ca3c214a
Author: Sandeep &lt;sandeepchoudhary1507@gmail.com&gt;
Date:   Sun Jun 14 01:06:07 2020 +0530

    New goals added

</code></pre>

<p>we can also run the rebase command in <strong>—interactive</strong> mode which gives us the option to edit/squash/... the commits</p>

<pre><code class="language-bash">&gt;&gt;&gt; git rebase -i master
pick 1848058 work around bugs

# Rebase 3c5d6ba..1848058 onto 3c5d6ba (1 command(s))
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like &#34;squash&#34;, but discard this commit&#39;s log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out

</code></pre>

<p>One of the cool use of the git rebase command is that you can change the base of the branch from one branch to other by use of
<strong>—onto</strong> option.</p>

<p>Let assume you create a branch <em>featureA</em> from master and then another branch <em>featureB</em> from <em>featureA</em>, to change the base of the featureB branch.</p>

<pre><code class="language-bash"># git rebase --onto &lt;newbase&gt; &lt;oldbase&gt;
&gt;&gt;&gt; git rebase --onto master featureA featureB
</code></pre>

<p>So this is all about the git rebase command, which can help you to keep your commit history clean and your current working branch commits sync with the master branch.</p>

<p><a href="/sandeepk/tag:git" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">git</span></a></p>
]]></content:encoded>
      <guid>https://blogs.dgplug.org/sandeepk/git-rebase</guid>
      <pubDate>Mon, 01 Jun 2020 18:37:23 +0000</pubDate>
    </item>
  </channel>
</rss>