<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>Version Control on entangledDEV</title>
        <link>/tags/version-control/</link>
        <description>Recent content in Version Control 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/version-control/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></channel>
</rss>
