<?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 Cheat Sheet</title><link>/tags/git/</link><description>Recent content in Git on Cheat Sheet</description><generator>Hugo</generator><language>en</language><atom:link href="/tags/git/index.xml" rel="self" type="application/rss+xml"/><item><title>Cheat Sheet</title><link>/dotfiles/git/cheat-sheet/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/dotfiles/git/cheat-sheet/</guid><description>&lt;h1 id="git-cheat-sheet"&gt;Git Cheat Sheet&lt;a class="anchor" href="#git-cheat-sheet"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;See also: &lt;a href="https://git-scm.com/cheat-sheet"&gt;Git Cheat Sheet&lt;/a&gt;&lt;/p&gt;
&lt;h2 id="setup-and-config"&gt;Setup and Config&lt;a class="anchor" href="#setup-and-config"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;git config&lt;/code&gt;&lt;/strong&gt;: Manage configuration options.
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Scope&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;--system&lt;/code&gt;: System-wide settings.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;--global&lt;/code&gt;: User-specific settings.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;--local&lt;/code&gt;: Repository-specific settings (default).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Verb&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;list --show-origin&lt;/code&gt;: List all settings and their source file.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Common Keys&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;user.name&lt;/code&gt;, &lt;code&gt;user.email&lt;/code&gt;: Identification.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;core.editor&lt;/code&gt;: Default text editor.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;init.defaultBranch&lt;/code&gt;: Default branch name for &lt;code&gt;git init&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;color.ui&lt;/code&gt;: Enable colored output.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;alias.&amp;lt;alias-name&amp;gt;&lt;/code&gt;: Create custom aliases (eg. &lt;code&gt;git config --global alias.co checkout&lt;/code&gt;). See &lt;a href="https://github.com/Jssim710/dotfiles/blob/main/4-git/.gitconfig_local"&gt;gitconfig&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;credential.helper&lt;/code&gt;: Cache or store credentials (eg. &lt;code&gt;cache&lt;/code&gt; or &lt;code&gt;store&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="start-a-working-area"&gt;Start a Working Area&lt;a class="anchor" href="#start-a-working-area"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;git init&lt;/code&gt;&lt;/strong&gt;: Initialize a new Git repository.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;git clone &amp;lt;repo&amp;gt; [&amp;lt;dir&amp;gt;]&lt;/code&gt;&lt;/strong&gt;: Clone a repository into a new directory.
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;-o &amp;lt;name&amp;gt;&lt;/code&gt;: Use &lt;code&gt;&amp;lt;name&amp;gt;&lt;/code&gt; instead of &lt;code&gt;origin&lt;/code&gt; to track upstream.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="work-on-the-current-change"&gt;Work on the Current Change&lt;a class="anchor" href="#work-on-the-current-change"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;git add &amp;lt;path&amp;gt;&lt;/code&gt;&lt;/strong&gt;: Add file contents to the index.
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;-i, --interactive&lt;/code&gt;: Interactive mode.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;-p, --patch&lt;/code&gt;: Interactive hunk selection.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;git restore &amp;lt;file&amp;gt;&lt;/code&gt;&lt;/strong&gt;: Restore working tree files.
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;--staged&lt;/code&gt;: Unstage a file.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;-p, --patch&lt;/code&gt;: Interactive hunk selection.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;git rm&lt;/code&gt;&lt;/strong&gt;: Remove files from the working tree and from the index (equivalent to &lt;code&gt;rm &amp;lt;file&amp;gt; &amp;amp;&amp;amp; git add &amp;lt;file&amp;gt;&lt;/code&gt;).
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;--cached&lt;/code&gt;: Remove from index only (stop tracking). Useful for removing accidentally committed files (eg. &lt;code&gt;git rm --cached .env&lt;/code&gt; then add &lt;code&gt;.env&lt;/code&gt; to &lt;code&gt;.gitignore&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;git mv &amp;lt;from&amp;gt; &amp;lt;to&amp;gt;&lt;/code&gt;&lt;/strong&gt;: Move or rename a file (equivalent to &lt;code&gt;mv &amp;lt;from&amp;gt; &amp;lt;to&amp;gt;&lt;/code&gt;, &lt;code&gt;git rm &amp;lt;from&amp;gt;&lt;/code&gt;, &lt;code&gt;git add &amp;lt;to&amp;gt;&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;git clean&lt;/code&gt;&lt;/strong&gt;: Remove untracked files from the working tree.
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;-n&lt;/code&gt;: Dry run (show what would be deleted).&lt;/li&gt;
&lt;li&gt;&lt;code&gt;-f&lt;/code&gt;: Force (required to perform deletion).&lt;/li&gt;
&lt;li&gt;&lt;code&gt;-d&lt;/code&gt;: Remove untracked directories as well.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;-x&lt;/code&gt;: Remove ignored files as well (eg. build artifacts).&lt;/li&gt;
&lt;li&gt;&lt;code&gt;-X&lt;/code&gt;: Remove &lt;em&gt;only&lt;/em&gt; ignored files.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="examine-the-history-and-state"&gt;Examine the History and State&lt;a class="anchor" href="#examine-the-history-and-state"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;See also: &lt;a href="../../dotfiles/git/revisions/"&gt;revisions&lt;/a&gt;&lt;/p&gt;</description></item><item><title>revisions</title><link>/dotfiles/git/revisions/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/dotfiles/git/revisions/</guid><description>&lt;h1 id="revisions"&gt;revisions&lt;a class="anchor" href="#revisions"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;See also: &lt;a href="https://git-scm.com/book/en/v2/Git-Tools-Revision-Selection"&gt;Pro Git - Revision Selection&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Git uses various symbols to refer to specific commits (references) or ranges of commits.&lt;/p&gt;
&lt;h2 id="relative-references"&gt;Relative References&lt;a class="anchor" href="#relative-references"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Use these to move through the commit history starting from a specific point (like &lt;code&gt;HEAD&lt;/code&gt;).&lt;/p&gt;
&lt;h3 id="-ancestor"&gt;&lt;code&gt;~&lt;/code&gt; (Ancestor)&lt;a class="anchor" href="#-ancestor"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Points to the n-th ancestor, following only the &lt;strong&gt;first parent&lt;/strong&gt; of each commit.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;HEAD~&lt;/code&gt;: The parent of &lt;code&gt;HEAD&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;HEAD~2&lt;/code&gt;: The grandparent (parent of the parent).&lt;/li&gt;
&lt;li&gt;&lt;code&gt;HEAD~&amp;lt;n&amp;gt;&lt;/code&gt;: The n-th ancestor.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="-parent"&gt;&lt;code&gt;^&lt;/code&gt; (Parent)&lt;a class="anchor" href="#-parent"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Points to the n-th parent of a commit. This is particularly useful for &lt;strong&gt;merge commits&lt;/strong&gt; which have multiple parents.&lt;/p&gt;</description></item><item><title>Submodule vs Worktree</title><link>/dotfiles/git/submodule-vs-worktree/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/dotfiles/git/submodule-vs-worktree/</guid><description>&lt;h1 id="submodule-vs-worktree"&gt;Submodule vs Worktree&lt;a class="anchor" href="#submodule-vs-worktree"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;h2 id="submodule"&gt;Submodule&lt;a class="anchor" href="#submodule"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Manages external repositories as subdirectories. It points to a specific commit and is suitable for dependency management such as libraries or themes.
eg. This blog manages the Hugo theme (&lt;code&gt;hugo-book&lt;/code&gt;) as a submodule.&lt;/p&gt;
&lt;h3 id="how-to-update-the-parent-repository"&gt;How to update the parent repository&lt;a class="anchor" href="#how-to-update-the-parent-repository"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;In the Standalone Submodule Repo&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;Perform work, commit, and push.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Note&lt;/strong&gt;: You never need &lt;code&gt;git sync&lt;/code&gt; here because there are no submodules. See &lt;a href="https://github.com/Jssim710/dotfiles/blob/main/4-git/.gitconfig_local"&gt;gitconfig&lt;/a&gt; for the alias definition.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;In the Parent Repo&lt;/strong&gt;:
&lt;ul&gt;
&lt;li&gt;Run &lt;code&gt;git submodule update --remote&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The parent repo will notice the submodule has moved to a new commit.&lt;/li&gt;
&lt;li&gt;Commit and push the new pointer in the parent repo.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id="worktree"&gt;Worktree&lt;a class="anchor" href="#worktree"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Creates multiple working directories from a single repository. Useful for working on multiple branches simultaneously, reducing context switching costs.&lt;/p&gt;</description></item><item><title>checkout, reset -&gt; switch, restore</title><link>/dotfiles/git/checkout-switch-restore-reset/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/dotfiles/git/checkout-switch-restore-reset/</guid><description>&lt;h1 id="checkout-reset---switch-restore"&gt;&lt;code&gt;checkout&lt;/code&gt;, &lt;code&gt;reset&lt;/code&gt; -&amp;gt; &lt;code&gt;switch&lt;/code&gt;, &lt;code&gt;restore&lt;/code&gt;&lt;a class="anchor" href="#checkout-reset---switch-restore"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;In Git 2.23, the overloaded &lt;code&gt;git checkout&lt;/code&gt; command was split into &lt;code&gt;git switch&lt;/code&gt; (for branch management) and &lt;code&gt;git restore&lt;/code&gt; (for file management) to make intentions clearer.&lt;/p&gt;
&lt;p&gt;While &lt;code&gt;git checkout&lt;/code&gt; is now fully replaced by these two commands, &lt;strong&gt;&lt;code&gt;git reset&lt;/code&gt; is only partially replaced&lt;/strong&gt; for its file-level operations (like unstaging). &lt;code&gt;git reset&lt;/code&gt; remains the primary tool for moving the branch pointer (&lt;code&gt;HEAD&lt;/code&gt;) to a different commit.&lt;/p&gt;</description></item><item><title>rebase</title><link>/dotfiles/git/rebase/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/dotfiles/git/rebase/</guid><description>&lt;h1 id="rebase"&gt;rebase&lt;a class="anchor" href="#rebase"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;h2 id="onto"&gt;&amp;ndash;onto&lt;a class="anchor" href="#onto"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The &lt;code&gt;--onto&lt;/code&gt; option allows you to take a range of commits from one branch and &amp;ldquo;transplant&amp;rdquo; them onto another, even if they do not share a direct parent-child relationship.&lt;/p&gt;
&lt;h3 id="usage"&gt;Usage&lt;a class="anchor" href="#usage"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="background-color:#f7f7f7;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$ git rebase --onto &amp;lt;newbase&amp;gt; &amp;lt;upstream&amp;gt; &amp;lt;branch&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;newbase&amp;gt;&lt;/code&gt;: The branch or commit where you want the changes to land.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;upstream&amp;gt;&lt;/code&gt;: The reference point to exclude history from. Git replays the range &lt;code&gt;&amp;lt;upstream&amp;gt;..&amp;lt;branch&amp;gt;&lt;/code&gt;, meaning everything reachable from &lt;code&gt;&amp;lt;branch&amp;gt;&lt;/code&gt; but &lt;strong&gt;not&lt;/strong&gt; reachable from &lt;code&gt;&amp;lt;upstream&amp;gt;&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;branch&amp;gt;&lt;/code&gt;: The branch containing the commits you want to move (optional if currently checked out).&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="how-it-differs-from-standard-rebase"&gt;How it differs from standard rebase&lt;a class="anchor" href="#how-it-differs-from-standard-rebase"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;A standard &lt;code&gt;git rebase &amp;lt;upstream&amp;gt;&lt;/code&gt; automatically identifies the &lt;strong&gt;common ancestor&lt;/strong&gt; between &lt;code&gt;&amp;lt;upstream&amp;gt;&lt;/code&gt; and the current branch. It then replays all commits that come after that ancestor onto the tip of &lt;code&gt;&amp;lt;upstream&amp;gt;&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>Branching and Merging</title><link>/dotfiles/git/branching-merging/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/dotfiles/git/branching-merging/</guid><description>&lt;h1 id="branching-and-merging"&gt;Branching and Merging&lt;a class="anchor" href="#branching-and-merging"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;h3 id="basic-merging"&gt;Basic Merging&lt;a class="anchor" href="#basic-merging"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;git switch &amp;lt;parent-branch&amp;gt; &amp;amp;&amp;amp; git merge &amp;lt;child-branch&amp;gt;&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Fast-forward&lt;/strong&gt;: If the parent branch has not moved, Git simply moves the pointer forward.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;git switch &amp;lt;child-branch&amp;gt; &amp;amp;&amp;amp; git merge &amp;lt;parent-branch&amp;gt;&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;Results in &amp;ldquo;Already up to date&amp;rdquo; if the parent is already an ancestor.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="3-way-merge"&gt;3-way Merge&lt;a class="anchor" href="#3-way-merge"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;When two branches have diverged, Git performs a 3-way merge using:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Common ancestor&lt;/li&gt;
&lt;li&gt;Current branch (Target)&lt;/li&gt;
&lt;li&gt;Source branch&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="squash-merge"&gt;Squash Merge&lt;a class="anchor" href="#squash-merge"&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;git merge --squash &amp;lt;branch&amp;gt;&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;Condenses all commits from the source branch into &lt;strong&gt;exactly one&lt;/strong&gt; new commit on the destination branch.&lt;/li&gt;
&lt;li&gt;Unlike a default merge which creates a merge commit with multiple parents to preserve history, a squash merge results in a linear and clean history.&lt;/li&gt;
&lt;li&gt;It does &lt;strong&gt;not&lt;/strong&gt; create a commit automatically. You must manually run &lt;code&gt;git commit&lt;/code&gt; to finalize the process.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;</description></item></channel></rss>