<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>Git on entangledDEV</title>
        <link>/tags/git/</link>
        <description>Recent content in Git on entangledDEV</description>
        <generator>Hugo -- gohugo.io</generator>
        <language>en-us</language>
        <lastBuildDate>Sun, 01 Feb 2026 00:09:25 -0600</lastBuildDate><atom:link href="/tags/git/index.xml" rel="self" type="application/rss+xml" /><item>
            <title>Git How-Tos I Reach For Daily Work</title>
            <link>/p/git-how-tos-i-reach-for-daily-work/</link>
            <pubDate>Mon, 27 Oct 2025 17:42:48 +0000</pubDate>
            <guid>/p/git-how-tos-i-reach-for-daily-work/</guid>
            <description>&lt;p&gt;This is my running log of Git moves I reach for when I do work. Each mini-how-to includes the exact commands plus a quick note on what to watch for.&lt;/p&gt;&#xA;&lt;h2 id=&#34;squash-multiple-commits-into-one&#34;&gt;&lt;a href=&#34;#squash-multiple-commits-into-one&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;Squash Multiple Commits Into One&#xA;&lt;/h2&gt;&lt;p&gt;Use interactive rebase to collapse the last &lt;em&gt;n&lt;/em&gt; commits into a single, tidy changeset.&lt;/p&gt;&#xA;&lt;p&gt;Optional safety: create a backup branch before rebasing:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git branch backup/feature-branch-before-squash&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git rebase -i HEAD~3&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Replace &lt;code&gt;3&lt;/code&gt; with however many commits you want to include, counting the current &lt;code&gt;HEAD&lt;/code&gt; as part of that total. &lt;code&gt;HEAD&lt;/code&gt; refers to the current commit, &lt;code&gt;HEAD~1&lt;/code&gt; to its parent, &lt;code&gt;HEAD~2&lt;/code&gt; to the one before that, and so on. When you run &lt;code&gt;git rebase -i HEAD~3&lt;/code&gt;, Git lists the last three commits including &lt;code&gt;HEAD&lt;/code&gt;. Run &lt;code&gt;git log --oneline&lt;/code&gt; to count backward until you reach the oldest commit you intend to squash.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Tip: Use &lt;code&gt;HEAD~3^&lt;/code&gt; if you need to include the fourth commit in the interactive list.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;For example, if your history looks like this (newest first):&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;a1b2c3 (HEAD)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;d4e5f6&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;g7h8i9&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;j0k1l2&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The command &lt;code&gt;git rebase -i HEAD~3&lt;/code&gt; opens the editor with:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;pick j0k1l2&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;pick g7h8i9&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;pick d4e5f6&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In the editor:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Leave the first commit as &lt;code&gt;pick&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;Change the rest to &lt;code&gt;squash&lt;/code&gt; (or &lt;code&gt;s&lt;/code&gt;)&lt;/li&gt;&#xA;&lt;li&gt;Save, then compose the final commit message&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;If conflicts appear, resolve them and resume with &lt;code&gt;git rebase --continue&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;To abort the squash at any point, run:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git rebase --abort&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;force-push-after-squashing&#34;&gt;&lt;a href=&#34;#force-push-after-squashing&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;Force Push After Squashing&#xA;&lt;/h2&gt;&lt;p&gt;Once history changes, update the remote branch.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git push --force-with-lease origin feature/my-branch&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;--force-with-lease&lt;/code&gt; protects teammates by refusing to overwrite work you haven’t fetched.&lt;/p&gt;&#xA;&lt;h2 id=&#34;create-a-local-repo-and-wire-up-a-remote&#34;&gt;&lt;a href=&#34;#create-a-local-repo-and-wire-up-a-remote&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;Create a Local Repo and Wire Up a Remote&#xA;&lt;/h2&gt;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;mkdir my-project &lt;span class=&#34;o&#34;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;cd&lt;/span&gt; my-project&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git init&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# add files, then commit&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git add .&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git commit -m &lt;span class=&#34;s2&#34;&gt;&amp;#34;Initial commit&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git remote add origin git@github.com:username/my-project.git&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git push -u origin main&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If the remote is empty, &lt;code&gt;main&lt;/code&gt; (or &lt;code&gt;master&lt;/code&gt;) becomes the default branch once you push with &lt;code&gt;-u&lt;/code&gt;. Double-check the URL format (&lt;code&gt;git@&lt;/code&gt; for SSH, &lt;code&gt;https://&lt;/code&gt; for HTTPS) before adding the remote.&lt;/p&gt;&#xA;&lt;h2 id=&#34;track-a-remote-branch-locally&#34;&gt;&lt;a href=&#34;#track-a-remote-branch-locally&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;Track a Remote Branch Locally&#xA;&lt;/h2&gt;&lt;p&gt;When you create a local branch that should follow an existing remote branch, set the upstream explicitly.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git switch -c feature/api-integration origin/feature/api-integration&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# or, if branch already exists locally&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git branch --set-upstream-to&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;origin/feature/api-integration&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now &lt;code&gt;git pull&lt;/code&gt; and &lt;code&gt;git push&lt;/code&gt; know which remote branch to use. If Git complains that the remote ref is missing, fetch it first (&lt;code&gt;git fetch origin feature/api-integration&lt;/code&gt;) and rerun the command.&lt;/p&gt;&#xA;&lt;h2 id=&#34;create-a-branch-and-push-it-upstream&#34;&gt;&lt;a href=&#34;#create-a-branch-and-push-it-upstream&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;Create a Branch and Push It Upstream&#xA;&lt;/h2&gt;&lt;p&gt;Shortcut to create a branch, commit, and publish it with upstream tracking in one go.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git switch -c feature/search-bar&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git commit -am &lt;span class=&#34;s2&#34;&gt;&amp;#34;Add search bar styles&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git push -u origin feature/search-bar&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;-u&lt;/code&gt; (or &lt;code&gt;--set-upstream&lt;/code&gt;) wires the remote for future pushes. Remember that &lt;code&gt;git commit -am&lt;/code&gt; only stages files Git already tracks—run &lt;code&gt;git add&lt;/code&gt; first if you created new files.&lt;/p&gt;&#xA;&lt;h2 id=&#34;sync-with-the-latest-from-main-without-merge-commits&#34;&gt;&lt;a href=&#34;#sync-with-the-latest-from-main-without-merge-commits&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;Sync With the Latest From Main Without Merge Commits&#xA;&lt;/h2&gt;&lt;p&gt;Rebase your current branch onto &lt;code&gt;main&lt;/code&gt; to replay your commits on top of the latest state.&lt;/p&gt;&#xA;&lt;p&gt;Optional safety: create a backup before rebasing:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git branch backup/feature-search-bar-before-rebase&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ol&gt;&#xA;&lt;li&gt;Make sure you have no pending edits: &lt;code&gt;git status -sb&lt;/code&gt; should report a clean tree.&lt;/li&gt;&#xA;&lt;li&gt;Update &lt;code&gt;main&lt;/code&gt; so you are rebasing onto the real latest code.&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git switch main&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git pull --ff-only origin main&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;&#xA;&lt;li&gt;Return to your feature branch (replace with your branch name).&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git switch feature/search-bar&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;&#xA;&lt;li&gt;Replay your commits on top of the freshly updated &lt;code&gt;main&lt;/code&gt;.&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git rebase main&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;⚠️ &lt;strong&gt;Rebase pointer:&lt;/strong&gt;&lt;br&gt;&#xA;In merges: ours = current branch, theirs = incoming.&lt;br&gt;&#xA;In rebases: ours = target branch, theirs = replayed commit.&lt;br&gt;&#xA;Pick the pieces you need, &lt;code&gt;git add&lt;/code&gt; each resolved file, and continue with &lt;code&gt;git rebase --continue&lt;/code&gt;.&lt;br&gt;&#xA;If the rebase turns chaotic, bail out with &lt;code&gt;git rebase --abort&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;Once the history looks right, rerun your tests and publish the new linear history:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git push --force-with-lease origin feature/search-bar&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If you prefer to preserve merge commits instead, use &lt;code&gt;git merge origin/main&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;h2 id=&#34;rebase-onto-the-remote-version-of-your-branch&#34;&gt;&lt;a href=&#34;#rebase-onto-the-remote-version-of-your-branch&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;Rebase Onto the Remote Version of Your Branch&#xA;&lt;/h2&gt;&lt;p&gt;When teammates update the remote feature branch, pull those commits in and resolve conflicts locally.&lt;/p&gt;&#xA;&lt;p&gt;Optional safety: create a backup before rebasing:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git branch backup/feature-payment-before-rebase&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ol&gt;&#xA;&lt;li&gt;Ensure a clean tree first: &lt;code&gt;git status -sb&lt;/code&gt;.&lt;/li&gt;&#xA;&lt;li&gt;Update your knowledge of the remote branch.&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git fetch origin feature/payment&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;&#xA;&lt;li&gt;Switch to your local branch that you want to replay.&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git switch feature/payment&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;&#xA;&lt;li&gt;Rebase onto the remote tracking branch you fetched.&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git rebase origin/feature/payment&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;⚠️ &lt;strong&gt;Rebase pointer:&lt;/strong&gt;&lt;br&gt;&#xA;In merges: ours = current branch, theirs = incoming.&lt;br&gt;&#xA;In rebases: ours = target branch, theirs = replayed commit.&lt;br&gt;&#xA;Merge the pieces you want, stage them with &lt;code&gt;git add&lt;/code&gt;, and continue (&lt;code&gt;git rebase --continue&lt;/code&gt;).&lt;br&gt;&#xA;If the rebase turns chaotic, bail out with &lt;code&gt;git rebase --abort&lt;/code&gt;.&lt;br&gt;&#xA;Alternatively, if your upstream is set, you can pull and rebase in one step:&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git pull --rebase&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;After the rebase, rerun tests and share the rewritten history safely:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git push --force-with-lease origin feature/payment&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;cherry-pick-a-fix-onto-another-branch&#34;&gt;&lt;a href=&#34;#cherry-pick-a-fix-onto-another-branch&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;Cherry-Pick a Fix Onto Another Branch&#xA;&lt;/h2&gt;&lt;p&gt;Grab a single commit and apply it elsewhere.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git switch release/1.2&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git cherry-pick &amp;lt;commit-sha&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If conflicts arise, fix them, &lt;code&gt;git add&lt;/code&gt; the files, and run &lt;code&gt;git cherry-pick --continue&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;For multiple commits, cherry-pick a range (the upper bound is exclusive):&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git cherry-pick A..B&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;blockquote&gt;&#xA;&lt;p&gt;Tip: Use &lt;code&gt;A^..B&lt;/code&gt; if you want to include commit &lt;code&gt;A&lt;/code&gt; itself.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;h2 id=&#34;quick-patch-from-a-file-diff&#34;&gt;&lt;a href=&#34;#quick-patch-from-a-file-diff&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;Quick Patch From a File Diff&#xA;&lt;/h2&gt;&lt;p&gt;Generate a patch for one file and drop it into another branch or repo.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git diff main..feature/payment checkout.swift &amp;gt; checkout.patch&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git switch hotfix/payment-crash&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git apply checkout.patch&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Review the applied changes before committing.&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;git apply&lt;/code&gt; only affects the working tree; follow up with &lt;code&gt;git add&lt;/code&gt; and &lt;code&gt;git commit&lt;/code&gt; once you confirm the patch looks right.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Tip: Run &lt;code&gt;git am checkout.patch&lt;/code&gt; instead if you want to preserve the original author and commit message from the patch.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;h2 id=&#34;merge-main-into-your-branch-keep-the-merge-commit&#34;&gt;&lt;a href=&#34;#merge-main-into-your-branch-keep-the-merge-commit&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;Merge Main Into Your Branch (Keep the Merge Commit)&#xA;&lt;/h2&gt;&lt;p&gt;If your team relies on merge commits for context, integrate the latest &lt;code&gt;main&lt;/code&gt; without rewriting history.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git fetch origin&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git merge --no-ff origin/main&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Resolve conflicts, run the test suite, and let Git create the merge commit message. &lt;code&gt;--no-ff&lt;/code&gt; retains the merge node even when a fast-forward is possible, preserving the branch narrative.&lt;/p&gt;&#xA;&lt;h2 id=&#34;see-what-changed-between-two-branches&#34;&gt;&lt;a href=&#34;#see-what-changed-between-two-branches&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;See What Changed Between Two Branches&#xA;&lt;/h2&gt;&lt;p&gt;Compare your feature branch to &lt;code&gt;main&lt;/code&gt;, highlighting only the files or commits that differ.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git log --oneline main..feature/billing&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git diff --stat main...feature/billing&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Two dots (&lt;code&gt;..&lt;/code&gt;) show unique commits; three dots (&lt;code&gt;...&lt;/code&gt;) reveal files that diverged from the common ancestor.&lt;/p&gt;&#xA;&lt;h2 id=&#34;undo-the-last-commit-keep-changes&#34;&gt;&lt;a href=&#34;#undo-the-last-commit-keep-changes&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;Undo the Last Commit (Keep Changes)&#xA;&lt;/h2&gt;&lt;p&gt;Keep your working tree but remove the most recent commit.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git reset --soft HEAD~1&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;HEAD&lt;/code&gt; is the current commit, so &lt;code&gt;HEAD~1&lt;/code&gt; targets the one before it. The changes remain staged. To unstage but keep edits, use &lt;code&gt;git reset --mixed HEAD~1&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;h2 id=&#34;recover-work-you-thought-was-gone&#34;&gt;&lt;a href=&#34;#recover-work-you-thought-was-gone&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;Recover Work You Thought Was Gone&#xA;&lt;/h2&gt;&lt;p&gt;If a commit vanished after a reset or rebase, scan the reflog.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git reflog&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;You can use &lt;code&gt;git show &amp;lt;reflog-sha&amp;gt;&lt;/code&gt; to inspect the commit before checking it out.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git switch --detach &amp;lt;reflog-sha&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Create a new branch from that SHA to rescue the work: &lt;code&gt;git switch -c rescue/forgotten &amp;lt;sha&amp;gt;&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;h2 id=&#34;stash-selective-files&#34;&gt;&lt;a href=&#34;#stash-selective-files&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;Stash Selective Files&#xA;&lt;/h2&gt;&lt;p&gt;Avoid stashing the whole tree by selecting specific paths.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git stash push -- src/HomeView.swift&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git stash list&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git stash pop&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Combine with &lt;code&gt;--keep-index&lt;/code&gt; to stash only unstaged changes.&#xA;Stashes are stored in order; use &lt;code&gt;git stash list&lt;/code&gt; to view entries and &lt;code&gt;git stash pop stash@{1}&lt;/code&gt; to apply a specific one.&lt;/p&gt;&#xA;&lt;h2 id=&#34;clean-untracked-files-safely&#34;&gt;&lt;a href=&#34;#clean-untracked-files-safely&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;Clean Untracked Files Safely&#xA;&lt;/h2&gt;&lt;p&gt;Preview deletions before scrubbing untracked files and directories.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git clean -nd&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git clean -fd&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;-n&lt;/code&gt; performs a dry run; &lt;code&gt;-f&lt;/code&gt; is required to delete, and &lt;code&gt;-d&lt;/code&gt; includes directories.&#xA;Double-check the dry-run output carefully—&lt;code&gt;git clean&lt;/code&gt; is irreversible once it runs with &lt;code&gt;-f&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;h2 id=&#34;revert-a-commit-that-already-hit-main&#34;&gt;&lt;a href=&#34;#revert-a-commit-that-already-hit-main&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;Revert a Commit That Already Hit Main&#xA;&lt;/h2&gt;&lt;p&gt;Create a new commit that undoes a previous one (keeps history intact).&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git revert &amp;lt;commit-sha&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Grab the commit SHA from &lt;code&gt;git log --oneline&lt;/code&gt;. If the revert itself fails because of conflicts, resolve them, &lt;code&gt;git add&lt;/code&gt; the files, and run &lt;code&gt;git revert --continue&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Tip: Need to revert several commits in one go? Use &lt;code&gt;git revert -n &amp;lt;sha1&amp;gt; &amp;lt;sha2&amp;gt; ...&lt;/code&gt; to stage the reversions and commit once at the end.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;h2 id=&#34;rename-a-branch-locally-and-remotely&#34;&gt;&lt;a href=&#34;#rename-a-branch-locally-and-remotely&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;Rename a Branch Locally and Remotely&#xA;&lt;/h2&gt;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git branch -m old-name new-name&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git push origin --delete old-name&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git push -u origin new-name&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If the branch is protected, you may need admin permissions (or to lift protection temporarily) before deleting it remotely. Afterwards, clean up stale references locally:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git fetch --prune&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Anyone else using the old branch should do the same and check out the new name.&lt;/p&gt;&#xA;&lt;hr&gt;&#xA;&lt;p&gt;I add to this page whenever I find myself repeating a Git flow. If you’re reading along and need another scenario covered, let me know and I’ll expand the list.&lt;/p&gt;&#xA;</description>
        </item><item>
            <title>Working With Git Submodules</title>
            <link>/p/working-with-git-submodules/</link>
            <pubDate>Wed, 25 Oct 2023 00:03:41 -0600</pubDate>
            <guid>/p/working-with-git-submodules/</guid>
            <description>&lt;p&gt;The other day, I was working on a project that had a Git submodule. Initially, I found it a bit tricky to make it work, so I decided to create a short tutorial on this.&lt;/p&gt;&#xA;&lt;h2 id=&#34;what-is-a-git-submodule&#34;&gt;&lt;a href=&#34;#what-is-a-git-submodule&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;What is a Git submodule&#xA;&lt;/h2&gt;&lt;p&gt;Essentially, a Git submodule is a way to include one Git repository inside another Git repository. This creates a nested structure.&lt;/p&gt;&#xA;&lt;p&gt;So, in simple words, a Git submodule is like a mini Git repository that you can include in your main Git repository to use and update external code or resources without actually putting all of their files directly in your project.&lt;/p&gt;&#xA;&lt;p&gt;The crucial point to note is that, by default, the code of the submodule is not added to your Git repository when performing the initial &lt;code&gt;git clone&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;h2 id=&#34;how-to-check-the-ulr-of-the-git-submodule&#34;&gt;&lt;a href=&#34;#how-to-check-the-ulr-of-the-git-submodule&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;How to check the ulr of the git submodule&#xA;&lt;/h2&gt;&lt;p&gt;To check the linked URLs of submodules we can use this command.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git config --file .gitmodules --get-regexp &lt;span class=&#34;s1&#34;&gt;&amp;#39;submodule\..*\.url&amp;#39;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;how-to-clone-a-submodule&#34;&gt;&lt;a href=&#34;#how-to-clone-a-submodule&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;How to clone a submodule&#xA;&lt;/h2&gt;&lt;p&gt;There could be three situations:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;You want to clone the git project with all its submodules for the first time.&lt;/li&gt;&#xA;&lt;li&gt;You&amp;rsquo;ve cloned the git project but didn&amp;rsquo;t fetch the submodules.&lt;/li&gt;&#xA;&lt;li&gt;You want to update the submodules in your project.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;h3 id=&#34;cloning-a-project-with-all-submodules-for-the-first-time&#34;&gt;&lt;a href=&#34;#cloning-a-project-with-all-submodules-for-the-first-time&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;Cloning a project with all submodules for the first time&#xA;&lt;/h3&gt;&lt;p&gt;If you want to clone a project for the first time with all its submodules, you can run the following command.&lt;/p&gt;&#xA;&lt;p&gt;With Git version 2.13 or newer.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git clone --recurse-submodules -j8 https://github.com/your/repo.git&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;blockquote&gt;&#xA;&lt;p&gt;&lt;code&gt;-j8&lt;/code&gt; is an optional performance optimization that became available in version 2.8, and fetches up to 8 submodules at a time in parallel&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;Before Git 2.12.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git clone --recursive https://github.com/your/repo.git&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&#34;cloning-the-submodules-only&#34;&gt;&lt;a href=&#34;#cloning-the-submodules-only&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;Cloning the submodules only&#xA;&lt;/h3&gt;&lt;p&gt;If you&amp;rsquo;ve downloaded the project but forgot to fetch the submodules, you can use this command.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git submodule update --init --recursive&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;blockquote&gt;&#xA;&lt;p&gt;If you&amp;rsquo;ve cloned only the main Git repository, you&amp;rsquo;ll be missing the submodule files, potentially causing your project to fail.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;h3 id=&#34;updating-the-submodules&#34;&gt;&lt;a href=&#34;#updating-the-submodules&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;Updating the submodules&#xA;&lt;/h3&gt;&lt;p&gt;If you want to update the code of the submodules, you need to run this command.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git submodule update --recursive --remote&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;blockquote&gt;&#xA;&lt;p&gt;This will only update the branch registered in the &lt;code&gt;.gitmodule&lt;/code&gt;, and by default, you will end up with a detached HEAD, unless &amp;ndash;rebase or &amp;ndash;merge is specified or the key submodule.$name.update is set to rebase, merge or none.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;h2 id=&#34;adding-a-submodule-to-a-git-repository&#34;&gt;&lt;a href=&#34;#adding-a-submodule-to-a-git-repository&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;Adding a submodule to a git repository&#xA;&lt;/h2&gt;&lt;p&gt;To add another remote Git repository as a submodule to your current Git repository, you can use this command.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git submodule add https://github.com/your/repo.git path/to_save/in_repo&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The provided code allows you to specify the remote URL for the repository you want to use as a submodule, as well as the path within your project where you want to save the cloned code.&lt;/p&gt;&#xA;&lt;h2 id=&#34;delete-a-git-submodule-from-your-project&#34;&gt;&lt;a href=&#34;#delete-a-git-submodule-from-your-project&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;Delete a Git submodule from your project&#xA;&lt;/h2&gt;&lt;p&gt;This process is common but not that straightforward, here are the steps you need to do.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;The files mentioned in the following steps are located in the root directory of your project, which is the default location for the Git files.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Delete the relevant line from the &lt;code&gt;.gitmodules&lt;/code&gt; file.&lt;/li&gt;&#xA;&lt;li&gt;Delete the relevant section from &lt;code&gt;.git/config&lt;/code&gt;.&lt;/li&gt;&#xA;&lt;li&gt;Run &lt;code&gt;git rm --cached path_to_submodule&lt;/code&gt; (no trailing slash).&lt;/li&gt;&#xA;&lt;li&gt;Commit and delete the now untracked submodule files.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;A trailing slash is the slash that can be added to the end of the path. &lt;code&gt;submodules/my_submodule/&lt;/code&gt; has a trailing slash while &lt;code&gt;submodules/my_submodule&lt;/code&gt; doesn&amp;rsquo;t have one.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;h2 id=&#34;conclusion&#34;&gt;&lt;a href=&#34;#conclusion&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;Conclusion&#xA;&lt;/h2&gt;&lt;p&gt;Git submodules are a powerful feature for managing dependencies in your projects. They allow you to include external Git repositories within your main repository without cluttering it with their files. This can be especially handy when you&amp;rsquo;re working on projects that rely on external code or resources.&lt;/p&gt;&#xA;&lt;p&gt;We&amp;rsquo;ve covered some essential aspects of working with Git submodules in this tutorial. You&amp;rsquo;ve learned what a Git submodule is and how to check the URLs of linked submodules. You also know how to clone a project with all its submodules, how to retrieve submodules if you&amp;rsquo;ve forgotten them, and how to keep them updated. Furthermore, we discussed adding and deleting a submodule from your Git repository.&lt;/p&gt;&#xA;&lt;p&gt;With this knowledge, you&amp;rsquo;ll be better equipped to manage complex projects with Git submodules and streamline your workflow. So, don&amp;rsquo;t shy away from using them in your projects when they can help you manage external code more efficiently.&lt;/p&gt;&#xA;&lt;p&gt;Happy coding 🚀!&lt;/p&gt;&#xA;</description>
        </item></channel>
</rss>
