📰 Tech News·Dev.to Trending·⬆ 108 points
10 Git Commands You’ll Wish You Knew Earlier
10 Git Commands You’ll Wish You Knew Earlier - DEV Community body:has(.pageslug-aie) #topbar { display: none !important; } @media screen and (max-width: 768px) and (pointer: coarse) { /* Target WebKit/Blink specific behaviors */ @supports (-webkit-app-region: none) { body:has(.pageslug-aie) .dc-page { padding-top: 56px !important; } } } body:not(.hidden-shell) .pageslug-aie { margin-top: -56px !important; } /* ========================================================================== THE 418 CHALLENGE: THEME-AWARE RETRO EDITION ========================================================================== */ .articletag-418challenge { font-family: "Comic Sans MS", "Chalkboard SE", "Marker Felt", sans-serif !important; cursor: crosshair !important; } /* Destroy modern rounded corners and add brutal borders */ .articletag-418challenge .crayons-card, .articletag-418challenge .crayons-article__main, .articletag-418challenge .crayons-article__header { border-radius: 0 !important; margin-bottom: 2rem !important; } /* Typography specifics */ .articletag-418challenge h1, .articletag-418challenge h2, .articletag-418challenge h3 { text-transform: uppercase !important; } /* Fake effect for the main article title */ .articletag-418challenge h1.fs-3xl { animation: retro-slide 5s linear infinite alternate; overflow: visible; } /* Spin those avatars */ .articletag-418challenge .crayons-article__header__meta img { border-radius: 0 !important; animation: retro-spin 5s linear infinite; } /* Obnoxious tags */ .articletag-418challenge .crayons-tag { border-radius: 0 !important; font-weight: 900 !important; transform: rotate(-3deg); display: inline-block; } .articletag-418challenge .crayons-tag:nth-child(even) { transform: rotate(3deg); } /* -------------------------------------------------------------------------- 2. LIGHT THEME (Windows 95 / Office 97 Vibes) -------------------------------------------------------------------------- */ body:not(.dark-theme) .articletag-418challenge { background-color: #008080 !important; /* Win95 Teal Desktop */ } body:not(.dark-theme) .articletag-418challenge .crayons-card, body:not(.dark-theme) .articletag-418challenge .crayons-article__main, body:not(.dark-theme) .articletag-418challenge .crayons-article__header { background-color: #c0c0c0 !important; /* Classic dialog gray */ color: #000000 !important; border: 4px outset #ffffff !important; box-shadow: 8px 8px 0px #000000 !important; } body:not(.dark-theme) .articletag-418challenge h1, body:not(.dark-theme) .articletag-418challenge h2, body:not(.dark-theme) .articletag-418challenge h3 { color: #ff0000 !important; text-shadow: 2px 2px 0px #ffff00 !important; border-bottom: 3px dashed #0000ff !important; } body:not(.dark-theme) .articletag-418challenge a, body:not(.dark-theme) .articletag-418challenge .crayons-link { color: #0000ff !important; /* Standard unvisited blue */ text-decoration: underline !important; font-weight: bold !important; } body:not(.dark-theme) .articletag-418challenge a:hover, body:not(.dark-theme) .articletag-418challenge .crayons-link:hover { background-color: #ffff00 !important; color: #ff0000 !important; } body:not(.dark-theme) .articletag-418challenge .crayons-tag { background: #ffff00 !important; color: #ff0000 !important; border: 2px dotted #0000ff !important; } /* -------------------------------------------------------------------------- 3. DARK THEME (1999 Hacker / Deep GeoCities Vibes) -------------------------------------------------------------------------- */ body.dark-theme .articletag-418challenge { background-color: #000000 !important; /* Dumb CSS: A scrolling, eye-bleeding neon green hacker grid with CRT scanlines */ background-image: linear-gradient(transparent 50%, rgba(0, 255, 0, 0.25) 50%), linear-gradient(90deg, rgba(0, 255, 0, 0.5) 1px, transparent 1px), linear-gradient(rgba(0, 255, 0, 0.5) 1px, transparent 1px) !important; background-size: 100% 4px, 20px 20px, 20px 20px !important; animation: retro-pan 60s linear infinite !important; } body.dark-theme .articletag-418challenge .crayons-card, body.dark-theme .articletag-418challenge .crayons-article__main, body.dark-theme .articletag-418challenge .crayons-article__header { background-color: #111111 !important; color: #00ff00 !important; /* Terminal Green */ border: 4px outset #555555 !important; box-shadow: 8px 8px 0px #ff00ff !important; /* Hot pink shadow */ } body.dark-theme .articletag-418challenge h1, body.dark-theme .articletag-418challenge h2, body.dark-theme .articletag-418challenge h3 { color: #ff00ff !important; /* Magenta headers */ text-shadow: 2px 2px 0px #00ffff !important; /* Cyan shadow */ border-bottom: 3px dashed #00ff00 !important; } body.dark-theme .articletag-418challenge a, body.dark-theme .articletag-418challenge .crayons-link { color: #00ffff !important; /* Cyan links */ text-decoration: underline !important; font-weight: bold !important; } body.dark-theme .articletag-418challenge a:hover, body.dark-theme .articletag-418challenge .crayons-link:hover { background-color: #ff00ff !important; color: #ffffff !important; } body.dark-theme .articletag-418challenge .crayons-tag { background: #000000 !important; color: #00ff00 !important; border: 2px dotted #ff00ff !important; } /* -------------------------------------------------------------------------- 4. ANIMATIONS -------------------------------------------------------------------------- */ @keyframes retro-spin { 100% { transform: rotate(360deg); } } @keyframes retro-slide { 0% { transform: translateX(-2%); } 100% { transform: translateX(2%); } } @keyframes retro-pan { 0% { background-position: 0 0, 0 0, 0 0; } /* Numbers must be multiples of the background-size (4px and 20px) to loop perfectly */ 100% { background-position: 0 100px, 40px 40px, 40px 40px; } } /* -------------------------------------------------------------------------- 5. BONUS: CAUTION TAPE REACTION BAR -------------------------------------------------------------------------- */ .articletag-418challenge .crayons-article-actions { background: repeating-linear-gradient( 45deg, #ffff00, #ffff00 10px, #000000 10px, #000000 20px ) !important; border: 4px solid #ff0000 !important; border-radius: 0 !important; } .articletag-418challenge .crayons-article-actions button { background:black; color: #ff00ff !important; } .articletag-418challenge .crayons-article-actions .crayons-reaction__count { color: #ff00ff !important; font-weight: bold !important; } .articletag-418challenge .crayons-icon:not(.crayons-icon--default) * { fill: #ffff00 !important; } .articletag-418challenge .c-embed .crayons-btn--primary { color: #00ff00 !important; } .articletag-418challenge .popover-billboard { margin-bottom: 0 !important; } .crayons-story__contentpreview .ltag__link--embedded { margin-top: 0 !important; } .subscription-icon { max-height: 16px !important; display: inline-block !important; } @media screen and (min-width: 950px) { .event-show-layout { margin-top: 24px !important; } } @media screen and (max-width: 949px) { .event-show-layout { padding: 11px !important; } } if (navigator.userAgent === 'ForemWebView/1' || window.frameElement) { document.body.classList.add("hidden-shell"); } if (new Date() > new Date("2026-02-04T09:00:00-05:00")) { document.body.dataset.sideNavVisible = "false"; } :root { --accent-brand-lighter-rgb: 86, 105, 285; --accent-brand-rgb: 64, 78, 211; --accent-brand-darker-rgb: 51, 62, 169; } Skip to content Navigation menu Search Powered by Algolia Search Log in Create account DEV Community Close .html-variant-wrapper { display: none} {"@context":"http://schema.org","@type":"Article","mainEntityOfPage":{"@type":"WebPage","@id":"https://dev.to/sylwia-lask/10-git-commands-youll-wish-you-knew-earlier-4fcp"},"url":"https://dev.to/sylwia-lask/10-git-commands-youll-wish-you-knew-earlier-4fcp","image":["https://media2.dev.to/dynamic/image/width=1080,height=1080,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fg32incg59t688pdez6il.png","https://media2.dev.to/dynamic/image/width=1280,height=720,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fg32incg59t688pdez6il.png","https://media2.dev.to/dynamic/image/width=1600,height=900,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fg32incg59t688pdez6il.png"],"publisher":{"@context":"http://schema.org","@type":"Organization","name":"DEV Community","logo":{"@context":"http://schema.org","@type":"ImageObject","url":"https://media2.dev.to/dynamic/image/width=192,height=,fit=scale-down,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8j7kvp660rqzt99zui8e.png","width":"192","height":"192"}},"headline":"10 Git Commands You’ll Wish You Knew Earlier","author":{"@context":"http://schema.org","@type":"Person","url":"https://dev.to/sylwia-lask","name":"Sylwia Laskowska"},"datePublished":"2026-08-26T07:59:06Z","dateModified":"2026-08-26T07:59:06Z","mainEntity":{"@type":"DiscussionForumPosting","@id":"#article-discussion-4488685","headline":"10 Git Commands You’ll Wish You Knew Earlier","text":"\u003cp\u003eDo you know Git? Of course you do! Today, I’ve got a few of my favorite Git commands for you. When I was a junior developer, my tech lead taught me most of them (hi Wojtek, if you’re reading this 👋) and later, I started teaching the same commands to my own junior and mid-level developers.\u003c/p\u003e\n\n\u003cp\u003eI’ve actually been meaning to write this article for months. But you know how it is. It’s evergreen content, it requires a bit of work, and meanwhile I kept coming up with other ideas, so I kept postponing it. What finally motivated me was \u003ca class=\"mentioned-user\" href=\"https://dev.to/francistrdev\"\u003e@francistrdev\u003c/a\u003e, who recently published his own article about Git commands.\u003c/p\u003e\n\n\u003cp\u003eMy article will be a little different, though. If you’re completely new to Git and still learning the basics, check out Francis’s \u003cstrong\u003e\u003ca href=\"https://dev.to/francistrdev/git-gud-4e6g\"\u003eGit Gud!\u003c/a\u003e\u003c/strong\u003e article first. But if \u003ccode\u003eadd\u003c/code\u003e, \u003ccode\u003ecommit\u003c/code\u003e, \u003ccode\u003epull\u003c/code\u003e, and \u003ccode\u003epush\u003c/code\u003e are already second nature to you, this article is for you.\u003c/p\u003e\n\n\u003cp\u003eThese are, let’s say, intermediate-level commands. Useful ones. The kind you actually need at work, but not yet senior-level Git magic like:\u003c/p\u003e\n\n\u003cblockquote\u003e\n\u003cp\u003eType three lines into your terminal and a spaceship will appear in your repository.\u003c/p\u003e\n\u003c/blockquote\u003e\n\n\u003cp\u003eIf you have other useful commands at this level, please share them in the comments!\u003c/p\u003e\n\n\u003cp\u003e\u003cem\u003eBTW, if you feel like it, you can also follow me on Instagram! I’m planning to post what could grandly be called “dev lifestyle” content there. 😅 I have four conferences coming up this fall, for example, so expect some behind-the-scenes photos from my little tour around Europe. I only have a handful of followers there so far and absolutely no idea what this experiment will turn into, but here you go: \u003ca href=\"https://www.instagram.com/sylwia.lask/\" target=\"_blank\" rel=\"noopener noreferrer\"\u003e@sylwia.lask\u003c/a\u003e\u003c/em\u003e\u003c/p\u003e\n\n\u003cp\u003eAll right, let’s start.\u003c/p\u003e\n\n\u003ch2\u003e\n \u003ca name=\"1-amp-2-raw-git-merge-endraw-vs-raw-git-rebase-endraw-\" href=\"#1-amp-2-raw-git-merge-endraw-vs-raw-git-rebase-endraw-\"\u003e\n \u003c/a\u003e\n 1. \u0026amp; 2. \u003ccode\u003egit merge\u003c/code\u003e vs \u003ccode\u003egit rebase\u003c/code\u003e\n\u003c/h2\u003e\n\n\u003cp\u003eHaha, first point and we already have two commands. The reason I’m putting them together is that a lot of developers, even experienced ones, treat \u003ccode\u003emerge\u003c/code\u003e and \u003ccode\u003erebase\u003c/code\u003e almost interchangeably.\u003c/p\u003e\n\n\u003cp\u003eAnd sure, their high-level purpose is similar: you want to integrate the history of one branch into another. Very often that means updating your feature branch with changes from \u003ccode\u003emain\u003c/code\u003e, \u003ccode\u003edevelop\u003c/code\u003e, or another feature branch.\u003c/p\u003e\n\n\u003cp\u003eBut the way they do it is quite different. Imagine you have this:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight plaintext\"\u003e\u003ccode\u003eA---B---C main\n \\\n D---E feature\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eYou’ve been happily working on your \u003ccode\u003efeature\u003c/code\u003e branch, while someone else added commit \u003ccode\u003eC\u003c/code\u003e to \u003ccode\u003emain\u003c/code\u003e. Now you want to bring those changes into your branch.\u003c/p\u003e\n\n\u003ch3\u003e\n \u003ca name=\"merge\" href=\"#merge\"\u003e\n \u003c/a\u003e\n Merge\n\u003c/h3\u003e\n\n\u003cp\u003eIf you run:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight shell\"\u003e\u003ccode\u003egit merge main\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003ewhile you’re on \u003ccode\u003efeature\u003c/code\u003e, Git combines both histories. You usually end up with something like this:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight plaintext\"\u003e\u003ccode\u003eA---B---C------M\n \\ /\n D---E---\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003e\u003ccode\u003eM\u003c/code\u003e is a merge commit.\u003c/p\u003e\n\n\u003cp\u003eThe original history stays intact. Git remembers that your feature branch diverged from \u003ccode\u003emain\u003c/code\u003e, both branches evolved independently for a while, and then they were joined together.\u003c/p\u003e\n\n\u003cp\u003eThis can be a good thing because it preserves the real history of what happened. The downside is that if you merge \u003ccode\u003emain\u003c/code\u003e into your feature branch over and over again, your history can eventually start looking like spaghetti.\u003c/p\u003e\n\n\u003ch3\u003e\n \u003ca name=\"rebase\" href=\"#rebase\"\u003e\n \u003c/a\u003e\n Rebase\n\u003c/h3\u003e\n\n\u003cp\u003eNow let’s say instead you run:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight shell\"\u003e\u003ccode\u003egit rebase main\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eGit takes commits \u003ccode\u003eD\u003c/code\u003e and \u003ccode\u003eE\u003c/code\u003e, temporarily removes them, moves your branch onto the latest \u003ccode\u003emain\u003c/code\u003e, and then reapplies your commits on top.\u003c/p\u003e\n\n\u003cp\u003eYou get:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight plaintext\"\u003e\u003ccode\u003eA---B---C---D'---E'\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eMuch cleaner.\u003c/p\u003e\n\n\u003cp\u003eBut notice the apostrophes. \u003ccode\u003eD'\u003c/code\u003e and \u003ccode\u003eE'\u003c/code\u003e are not technically the same commits as \u003ccode\u003eD\u003c/code\u003e and \u003ccode\u003eE\u003c/code\u003e. Git created new commits with new hashes. That means \u003cstrong\u003erebase rewrites history\u003c/strong\u003e.\u003c/p\u003e\n\n\u003cp\u003eThis is why a very useful rule of thumb is:\u003c/p\u003e\n\n\u003cblockquote\u003e\n\u003cp\u003eRebase your own work. Be careful rebasing shared history.\u003c/p\u003e\n\u003c/blockquote\u003e\n\n\u003cp\u003eIf you’re working alone on a feature branch, rebasing it is usually perfectly fine. If three other developers have already based their work on your commits, rebasing those commits can make everyone’s life considerably more exciting. And not in a good way. \u003c/p\u003e\n\n\u003ch3\u003e\n \u003ca name=\"and-what-about-conflicts\" href=\"#and-what-about-conflicts\"\u003e\n \u003c/a\u003e\n And what about conflicts?\n\u003c/h3\u003e\n\n\u003cp\u003eBoth merge and rebase can result in conflicts. \u003c/p\u003e\n\n\u003cp\u003eWith a merge, Git tries to combine the two histories in one operation. You resolve the conflicting files, stage them:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight shell\"\u003e\u003ccode\u003egit add \u003cspan class=\"nb\"\u003e.\u003c/span\u003e\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eand then continue:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight shell\"\u003e\u003ccode\u003egit merge \u003cspan class=\"nt\"\u003e--continue\u003c/span\u003e\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eWith rebase, things can be slightly more annoying because Git reapplies your commits one by one.\u003c/p\u003e\n\n\u003cp\u003eThis means you may resolve a conflict, continue the rebase...\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight shell\"\u003e\u003ccode\u003egit add \u003cspan class=\"nb\"\u003e.\u003c/span\u003e\ngit rebase \u003cspan class=\"nt\"\u003e--continue\u003c/span\u003e\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003e...and then get another conflict in the next commit. And another one. And another one. At which point you start questioning every career decision that led you here. 😅\u003c/p\u003e\n\n\u003cp\u003eBut there’s also a small bonus. If you completely mess things up and just want to stop the entire circus, you can do:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight shell\"\u003e\u003ccode\u003egit merge \u003cspan class=\"nt\"\u003e--abort\u003c/span\u003e\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eor:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight shell\"\u003e\u003ccode\u003egit rebase \u003cspan class=\"nt\"\u003e--abort\u003c/span\u003e\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eGit will try to return you to the state from before the merge or rebase started. Extremely useful feature. 😁\u003c/p\u003e\n\n\n\u003chr\u003e\n\n\u003ch2\u003e\n \u003ca name=\"3-raw-git-commit-amend-endraw-\" href=\"#3-raw-git-commit-amend-endraw-\"\u003e\n \u003c/a\u003e\n 3. \u003ccode\u003egit commit --amend\u003c/code\u003e\n\u003c/h2\u003e\n\n\u003cp\u003eThis is one of those commands I learned to love very quickly as a junior. Imagine you’ve just created a beautiful, perfectly round little commit. Then you look at the code and notice you forgot something.In my case, it was usually:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight javascript\"\u003e\u003ccode\u003e\u003cspan class=\"nx\"\u003econsole\u003c/span\u003e\u003cspan class=\"p\"\u003e.\u003c/span\u003e\u003cspan class=\"nf\"\u003elog\u003c/span\u003e\u003cspan class=\"p\"\u003e(\u003c/span\u003e\u003cspan class=\"dl\"\u003e\"\u003c/span\u003e\u003cspan class=\"s2\"\u003eWTF\u003c/span\u003e\u003cspan class=\"dl\"\u003e\"\u003c/span\u003e\u003cspan class=\"p\"\u003e);\u003c/span\u003e\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eYou now have two options. Option one: make another glorious commit:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight plaintext\"\u003e\u003ccode\u003eRemove console log\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eWhich, let’s be honest, is not exactly the pinnacle of Git history aesthetics. \u003c/p\u003e\n\n\u003cp\u003eOr you can simply add the forgotten change to the previous commit. For example:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight shell\"\u003e\u003ccode\u003egit add forgotten-file.ts\ngit commit \u003cspan class=\"nt\"\u003e--amend\u003c/span\u003e \u003cspan class=\"nt\"\u003e--no-edit\u003c/span\u003e\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003e\u003ccode\u003e--no-edit\u003c/code\u003e means:\u003c/p\u003e\n\n\u003cblockquote\u003e\n\u003cp\u003eAdd these changes to the previous commit, but keep the existing commit message.\u003c/p\u003e\n\u003c/blockquote\u003e\n\n\u003cp\u003eIf you want to change the commit message as well, just run:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight shell\"\u003e\u003ccode\u003egit commit \u003cspan class=\"nt\"\u003e--amend\u003c/span\u003e\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eGit will open your configured editor and let you modify it.\u003c/p\u003e\n\n\u003cp\u003eThere is one important detail here. \u003ccode\u003eamend\u003c/code\u003e doesn’t literally edit the existing commit. It creates a \u003cstrong\u003enew commit\u003c/strong\u003e containing the updated contents. And because commit hashes depend on the contents and metadata of the commit, the hash changes.\u003c/p\u003e\n\n\u003cp\u003eIf you’re working locally and haven’t pushed the branch anywhere yet, no problem. But if the branch already exists on remote, your local history no longer matches the remote history. So when you try:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight shell\"\u003e\u003ccode\u003egit push\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eyou’ll probably get something like:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight plaintext\"\u003e\u003ccode\u003erejected (non-fast-forward)\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eNow, if you are absolutely sure nobody else is working on that branch, you could technically do:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight shell\"\u003e\u003ccode\u003egit push \u003cspan class=\"nt\"\u003e--force\u003c/span\u003e\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eBut what if you’re not sure?\u003c/p\u003e\n\n\u003cp\u003eAnd this brings us very smoothly to the next point.\u003c/p\u003e\n\n\n\u003chr\u003e\n\n\u003ch2\u003e\n \u003ca name=\"4-raw-git-push-forcewithlease-endraw-\" href=\"#4-raw-git-push-forcewithlease-endraw-\"\u003e\n \u003c/a\u003e\n 4. \u003ccode\u003egit push --force-with-lease\u003c/code\u003e\n\u003c/h2\u003e\n\n\u003cp\u003eAfter a rebase, amend, interactive rebase, squash, or anything else that rewrites your commits, your local branch history may no longer match the version stored on remote.\u003c/p\u003e\n\n\u003cp\u003eYou can solve that with:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight shell\"\u003e\u003ccode\u003egit push \u003cspan class=\"nt\"\u003e--force\u003c/span\u003e\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eBut \u003ccode\u003e--force\u003c/code\u003e is basically saying:\u003c/p\u003e\n\n\u003cblockquote\u003e\n\u003cp\u003eMy local version is the truth. Replace whatever is on remote with this.\u003c/p\u003e\n\u003c/blockquote\u003e\n\n\u003cp\u003eIf someone pushed something to that branch in the meantime, you can overwrite their work. They may get angry. And rightly so. 😏\u003c/p\u003e\n\n\u003cp\u003eA much safer option is:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight shell\"\u003e\u003ccode\u003egit push \u003cspan class=\"nt\"\u003e--force-with-lease\u003c/span\u003e\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eIn simplified terms, this tells Git:\u003c/p\u003e\n\n\u003cblockquote\u003e\n\u003cp\u003eForce-push my version, but only if the remote branch still looks the way I expect it to.\u003c/p\u003e\n\u003c/blockquote\u003e\n\n\u003cp\u003eIf the remote branch changed since the state your local Git knows about, for example because someone else pushed new commits, Git refuses the push instead of blindly overwriting them.\u003c/p\u003e\n\n\u003cp\u003eSo instead of destroying someone’s afternoon, you get an error. I generally recommend:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight plaintext\"\u003e\u003ccode\u003e--force-with-lease\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eover:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight plaintext\"\u003e\u003ccode\u003e--force\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003ewhenever possible.\u003c/p\u003e\n\n\n\u003chr\u003e\n\n\u003ch2\u003e\n \u003ca name=\"5-raw-git-rebase-i-endraw-\" href=\"#5-raw-git-rebase-i-endraw-\"\u003e\n \u003c/a\u003e\n 5. \u003ccode\u003egit rebase -i\u003c/code\u003e\n\u003c/h2\u003e\n\n\u003cp\u003eFor me, this is a very important command. Almost the king of Git. xDDDD Interactive rebase lets you do almost anything you want with your recent commits.\u003c/p\u003e\n\n\u003cp\u003eIn other words, you can commit every single line individually, change everything ten times, create commits like:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight plaintext\"\u003e\u003ccode\u003eAdd validation\nFix validation\nActually fix validation\nFix validation again\nRemove console.log\nPlease work now\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eand then later turn the whole mess into an elegant Git history.\u003c/p\u003e\n\n\u003cp\u003eLet’s say you want to edit your last five commits. You run:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight shell\"\u003e\u003ccode\u003egit rebase \u003cspan class=\"nt\"\u003e-i\u003c/span\u003e HEAD~5\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eGit opens your configured editor — Vim, Nano, VS Code, or whatever you use — and shows something similar to:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight plaintext\"\u003e\u003ccode\u003epick a111111 Add login form\npick b222222 Add validation\npick c333333 Fix typo\npick d444444 Fix validation\npick e555555 Remove debug log\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eNow comes the fun part. You can replace \u003ccode\u003epick\u003c/code\u003e with different commands.\u003c/p\u003e\n\n\u003ch3\u003e\n \u003ca name=\"-raw-pick-endraw-\" href=\"#-raw-pick-endraw-\"\u003e\n \u003c/a\u003e\n \u003ccode\u003epick\u003c/code\u003e\n\u003c/h3\u003e\n\n\u003cp\u003eKeep the commit exactly as it is.\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight plaintext\"\u003e\u003ccode\u003epick a111111 Add login form\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003ch3\u003e\n \u003ca name=\"-raw-reword-endraw-\" href=\"#-raw-reword-endraw-\"\u003e\n \u003c/a\u003e\n \u003ccode\u003ereword\u003c/code\u003e\n\u003c/h3\u003e\n\n\u003cp\u003eKeep the commit contents, but change its message.\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight plaintext\"\u003e\u003ccode\u003ereword a111111 Add beautiful login form\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003ch3\u003e\n \u003ca name=\"-raw-edit-endraw-\" href=\"#-raw-edit-endraw-\"\u003e\n \u003c/a\u003e\n \u003ccode\u003eedit\u003c/code\u003e\n\u003c/h3\u003e\n\n\u003cp\u003ePause the rebase at that commit and let you modify it. Useful if you want to change the actual contents of an older commit.\u003c/p\u003e\n\n\u003ch3\u003e\n \u003ca name=\"-raw-squash-endraw-\" href=\"#-raw-squash-endraw-\"\u003e\n \u003c/a\u003e\n \u003ccode\u003esquash\u003c/code\u003e\n\u003c/h3\u003e\n\n\u003cp\u003eCombine the commit with the one before it.\u003c/p\u003e\n\n\u003cp\u003eFor example:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight plaintext\"\u003e\u003ccode\u003epick a111111 Add login form\nsquash b222222 Add validation\nsquash c333333 Fix validation\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eGit turns those commits into one and lets you edit the final commit message.\u003c/p\u003e\n\n\u003cp\u003eSo instead of:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight plaintext\"\u003e\u003ccode\u003eAdd login form\nAdd validation\nFix validation\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eyou can end up with:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight plaintext\"\u003e\u003ccode\u003eAdd login form with validation\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eBeautiful. Round. Perfect. \u003c/p\u003e\n\n\u003ch3\u003e\n \u003ca name=\"-raw-fixup-endraw-\" href=\"#-raw-fixup-endraw-\"\u003e\n \u003c/a\u003e\n \u003ccode\u003efixup\u003c/code\u003e\n\u003c/h3\u003e\n\n\u003cp\u003e\u003ccode\u003efixup\u003c/code\u003e is similar to \u003ccode\u003esquash\u003c/code\u003e, but it throws away the commit message of the fixup commit.\u003c/p\u003e\n\n\u003cp\u003eFor example:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight plaintext\"\u003e\u003ccode\u003epick a111111 Add login form\nfixup b222222 Fix typo\nfixup c333333 Remove console.log\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eYou probably don’t care about preserving the historical significance of:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight plaintext\"\u003e\u003ccode\u003eRemove console.log\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eSo \u003ccode\u003efixup\u003c/code\u003e is perfect here.\u003c/p\u003e\n\n\u003ch3\u003e\n \u003ca name=\"-raw-drop-endraw-\" href=\"#-raw-drop-endraw-\"\u003e\n \u003c/a\u003e\n \u003ccode\u003edrop\u003c/code\u003e\n\u003c/h3\u003e\n\n\u003cp\u003eRemove the commit completely.\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight plaintext\"\u003e\u003ccode\u003edrop c333333 Terrible idea\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eGoodbye.\u003c/p\u003e\n\n\u003cp\u003eOf course, there are different schools of thought about how much you should clean up your commits. Some senior developers say that submitting a nicely cleaned-up commit history for review is simply good manners. Others do not care in the slightest and think it’s unnecessary because GitHub, GitLab, or whatever platform you use can simply squash everything when merging the PR anyway.\u003c/p\u003e\n\n\u003cp\u003eBut!!! What if you don’t want to click \u003cstrong\u003eSquash and merge\u003c/strong\u003e? What if your feature logically contains two commits and you actually want to preserve both? That happens.\u003c/p\u003e\n\n\u003cp\u003eSo whether you use interactive rebase once a week or once every six months, I still think it’s worth knowing the king:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight shell\"\u003e\u003ccode\u003egit rebase \u003cspan class=\"nt\"\u003e-i\u003c/span\u003e\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\n\u003chr\u003e\n\n\u003ch2\u003e\n \u003ca name=\"6-raw-git-stash-endraw-\" href=\"#6-raw-git-stash-endraw-\"\u003e\n \u003c/a\u003e\n 6. \u003ccode\u003egit stash\u003c/code\u003e\n\u003c/h2\u003e\n\n\u003cp\u003eThis one comes in handy very often. You start working on a nice little feature. Or, these days, Kiro or Claude Code is working very hard while you watch. Suddenly someone reports a production bug.\u003c/p\u003e\n\n\u003cp\u003eUnfortunately, you now have to temporarily abandon your beautiful feature and switch to something else. The problem is that your current work is completely unfinished. You have debug logs everywhere, half the files are modified, the project doesn’t even build, and you definitely don’t want to commit this mess.\u003c/p\u003e\n\n\u003cp\u003eAlthough, of course, now you know about \u003ccode\u003eamend\u003c/code\u003e, so you could eventually clean it up. \u003c/p\u003e\n\n\u003cp\u003eBut there’s a better solution:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight shell\"\u003e\u003ccode\u003egit stash\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eGit temporarily stores your uncommitted changes and returns your working directory to a clean state.\u003c/p\u003e\n\n\u003cp\u003eNow you can switch branches:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight shell\"\u003e\u003ccode\u003egit switch main\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003efix your production disaster, and later come back.\u003c/p\u003e\n\n\u003cp\u003eOne important detail: by default, \u003ccode\u003egit stash\u003c/code\u003e stashes tracked files, but not new untracked files. If you also want to include newly created files, use:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight shell\"\u003e\u003ccode\u003egit stash \u003cspan class=\"nt\"\u003e-u\u003c/span\u003e\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eor, even better, give your stash a useful name:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight shell\"\u003e\u003ccode\u003egit stash push \u003cspan class=\"nt\"\u003e-u\u003c/span\u003e \u003cspan class=\"nt\"\u003e-m\u003c/span\u003e \u003cspan class=\"s2\"\u003e\"WIP login feature\"\u003c/span\u003e\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eBecause once you have several stashes named basically “WIP”, future you will hate present you.\u003c/p\u003e\n\n\u003ch3\u003e\n \u003ca name=\"-raw-git-stash-list-endraw-\" href=\"#-raw-git-stash-list-endraw-\"\u003e\n \u003c/a\u003e\n \u003ccode\u003egit stash list\u003c/code\u003e\n\u003c/h3\u003e\n\n\u003cp\u003eTo see all your stashes:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight shell\"\u003e\u003ccode\u003egit stash list\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eYou might get:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight plaintext\"\u003e\u003ccode\u003estash@{0}: On feature/login: WIP login feature\nstash@{1}: On feature/cart: experiment\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003ch3\u003e\n \u003ca name=\"-raw-git-stash-show-endraw-\" href=\"#-raw-git-stash-show-endraw-\"\u003e\n \u003c/a\u003e\n \u003ccode\u003egit stash show\u003c/code\u003e\n\u003c/h3\u003e\n\n\u003cp\u003eTo see what a particular stash contains:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight shell\"\u003e\u003ccode\u003egit stash show stash@\u003cspan class=\"o\"\u003e{\u003c/span\u003e0\u003cspan class=\"o\"\u003e}\u003c/span\u003e\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eAnd if you want the full diff:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight shell\"\u003e\u003ccode\u003egit stash show \u003cspan class=\"nt\"\u003e-p\u003c/span\u003e stash@\u003cspan class=\"o\"\u003e{\u003c/span\u003e0\u003cspan class=\"o\"\u003e}\u003c/span\u003e\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003ch3\u003e\n \u003ca name=\"-raw-git-stash-apply-endraw-\" href=\"#-raw-git-stash-apply-endraw-\"\u003e\n \u003c/a\u003e\n \u003ccode\u003egit stash apply\u003c/code\u003e\n\u003c/h3\u003e\n\n\u003cp\u003eTo restore a stash:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight shell\"\u003e\u003ccode\u003egit stash apply stash@\u003cspan class=\"o\"\u003e{\u003c/span\u003e0\u003cspan class=\"o\"\u003e}\u003c/span\u003e\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eThe changes are restored, but the stash remains in the list.\u003c/p\u003e\n\n\u003ch3\u003e\n \u003ca name=\"-raw-git-stash-pop-endraw-\" href=\"#-raw-git-stash-pop-endraw-\"\u003e\n \u003c/a\u003e\n \u003ccode\u003egit stash pop\u003c/code\u003e\n\u003c/h3\u003e\n\n\u003cp\u003eYou can also use:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight shell\"\u003e\u003ccode\u003egit stash pop\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eThis applies the stash and, if successful, removes it from the stash list.\u003c/p\u003e\n\n\u003cp\u003eSo, roughly:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight plaintext\"\u003e\u003ccode\u003eapply = restore\npop = restore + remove from stash\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eVery simple, very useful.\u003c/p\u003e\n\n\n\u003chr\u003e\n\n\u003ch2\u003e\n \u003ca name=\"7-raw-git-cherrypick-endraw-\" href=\"#7-raw-git-cherrypick-endraw-\"\u003e\n \u003c/a\u003e\n 7. \u003ccode\u003egit cherry-pick\u003c/code\u003e\n\u003c/h2\u003e\n\n\u003cp\u003eI have to admit this is one of the intermediate Git commands I use most often. Imagine there’s one specific commit on another branch that you want in your current branch.\u003c/p\u003e\n\n\u003cp\u003eYou don’t want to merge the whole branch. You don’t want to rebase onto it. You literally need one thing. For example, in my project recently, I needed a commit containing configuration for newly created environments. Perfect use case.\u003c/p\u003e\n\n\u003cp\u003eYou simply run:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight shell\"\u003e\u003ccode\u003egit cherry-pick \u0026lt;commit-hash\u0026gt;\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eFor example:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight shell\"\u003e\u003ccode\u003egit cherry-pick a1b2c3d\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eGit takes the changes introduced by that commit and applies them to your current branch.\u003c/p\u003e\n\n\u003cp\u003eImportant detail: it creates a \u003cstrong\u003enew commit\u003c/strong\u003e. So the resulting commit contains essentially the same changes, but it gets a new hash. Imagine this history:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight plaintext\"\u003e\u003ccode\u003emain\nA---B---C\n\nfeature\n \\\n D---E---F\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eYou’re on \u003ccode\u003emain\u003c/code\u003e, but you only want \u003ccode\u003eE\u003c/code\u003e.\u003c/p\u003e\n\n\u003cp\u003eAfter:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight shell\"\u003e\u003ccode\u003egit cherry-pick E\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eyou get something like:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight plaintext\"\u003e\u003ccode\u003eA---B---C---E'\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eSimple.\u003c/p\u003e\n\n\u003cp\u003eBut I’ll admit that, being a lazy creature, I use cherry-pick in slightly less noble ways too. Sometimes something gets completely messed up on my branch. The rebase goes badly, the history looks suspicious, conflicts start multiplying, and after a while I decide: I'll create a completely new branch from the correct place at the top of the tree. 😅\u003c/p\u003e\n\n\u003cp\u003eAnd because — thanks to the previous commands ☺️ — my commits are already nice and round, I simply cherry-pick them one by one onto the new branch.\u003c/p\u003e\n\n\u003cp\u003eI’m sure some Git pro is currently shaking their head at me, but let me put it this way: It works for me. 😀\u003c/p\u003e\n\n\n\u003chr\u003e\n\n\u003ch2\u003e\n \u003ca name=\"8-raw-git-reset-soft-endraw-raw-mixed-endraw-raw-hard-endraw-\" href=\"#8-raw-git-reset-soft-endraw-raw-mixed-endraw-raw-hard-endraw-\"\u003e\n \u003c/a\u003e\n 8. \u003ccode\u003egit reset --soft\u003c/code\u003e, \u003ccode\u003e--mixed\u003c/code\u003e, \u003ccode\u003e--hard\u003c/code\u003e\n\u003c/h2\u003e\n\n\u003cp\u003eThree ways of moving back in history, each with a different answer to the question:\u003c/p\u003e\n\n\u003cblockquote\u003e\n\u003cp\u003eWhat should happen to my changes?\u003c/p\u003e\n\u003c/blockquote\u003e\n\n\u003cp\u003eBecause how many times do we start working on something, write some code, and then realize: Nope. This whole idea was bad. Let’s go back.\u003c/p\u003e\n\n\u003cp\u003eThe easiest way to understand \u003ccode\u003ereset\u003c/code\u003e is to think about three layers:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight plaintext\"\u003e\u003ccode\u003eCommit history\nStaging area\nWorking directory\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eNow we have three increasingly dramatic levels of reset. And every next one has greater potential to cause a small heart attack if you use the wrong one. \u003c/p\u003e\n\n\u003ch3\u003e\n \u003ca name=\"-raw-git-reset-soft-endraw-\" href=\"#-raw-git-reset-soft-endraw-\"\u003e\n \u003c/a\u003e\n \u003ccode\u003egit reset --soft\u003c/code\u003e\n\u003c/h3\u003e\n\n\u003cp\u003eLet’s say you want to undo the last commit:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight shell\"\u003e\u003ccode\u003egit reset \u003cspan class=\"nt\"\u003e--soft\u003c/span\u003e HEAD~1\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eGit moves \u003ccode\u003eHEAD\u003c/code\u003e back by one commit, but all the changes from the removed commit remain \u003cstrong\u003estaged\u003c/strong\u003e.\u003c/p\u003e\n\n\u003cp\u003eSo if your history was:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight plaintext\"\u003e\u003ccode\u003eA---B\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eafter the reset, your branch points to:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight plaintext\"\u003e\u003ccode\u003eA\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003ebut the changes introduced by \u003ccode\u003eB\u003c/code\u003e are still ready to commit.\u003c/p\u003e\n\n\u003cp\u003eThis is useful when you committed too early and want to recreate the commit differently.\u003c/p\u003e\n\n\u003ch3\u003e\n \u003ca name=\"-raw-git-reset-mixed-endraw-\" href=\"#-raw-git-reset-mixed-endraw-\"\u003e\n \u003c/a\u003e\n \u003ccode\u003egit reset --mixed\u003c/code\u003e\n\u003c/h3\u003e\n\n\u003cp\u003eNow:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight shell\"\u003e\u003ccode\u003egit reset \u003cspan class=\"nt\"\u003e--mixed\u003c/span\u003e HEAD~1\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eor simply:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight shell\"\u003e\u003ccode\u003egit reset HEAD~1\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003ebecause \u003ccode\u003e--mixed\u003c/code\u003e is the default.\u003c/p\u003e\n\n\u003cp\u003eAgain, Git moves back one commit.\u003c/p\u003e\n\n\u003cp\u003eBut this time the changes are left in your working directory \u003cstrong\u003eunstaged\u003c/strong\u003e.\u003c/p\u003e\n\n\u003cp\u003eSo nothing disappears from your files, but you need to \u003ccode\u003egit add\u003c/code\u003e things again before committing.\u003c/p\u003e\n\n\u003ch3\u003e\n \u003ca name=\"-raw-git-reset-hard-endraw-\" href=\"#-raw-git-reset-hard-endraw-\"\u003e\n \u003c/a\u003e\n \u003ccode\u003egit reset --hard\u003c/code\u003e\n\u003c/h3\u003e\n\n\u003cp\u003eAnd now we enter the danger zone:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight shell\"\u003e\u003ccode\u003egit reset \u003cspan class=\"nt\"\u003e--hard\u003c/span\u003e HEAD~1\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eThis moves \u003ccode\u003eHEAD\u003c/code\u003e back and updates both the staging area and working directory to match that commit. In other words, the changes disappear from your files too.\u003c/p\u003e\n\n\u003cp\u003eSo:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight plaintext\"\u003e\u003ccode\u003e--soft → keep changes staged\n--mixed → keep changes unstaged\n--hard → discard changes from the working tree\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eUse the last one with some awareness of what you’re doing. But what if you go one step too far and accidentally delete something you absolutely did not mean to delete?\u003c/p\u003e\n\n\u003cp\u003eAnd that brings us to...\u003c/p\u003e\n\n\n\u003chr\u003e\n\n\u003ch2\u003e\n \u003ca name=\"9-raw-git-reflog-endraw-\" href=\"#9-raw-git-reflog-endraw-\"\u003e\n \u003c/a\u003e\n 9. \u003ccode\u003egit reflog\u003c/code\u003e\n\u003c/h2\u003e\n\n\u003cp\u003eA command I use very rarely. But oh, how many times it has saved my ass.\u003c/p\u003e\n\n\u003cp\u003eFor example, when I once ran \u003ccode\u003egit reset --hard\u003c/code\u003e and instead of removing my last changes, I basically removed the branch I had been working on for two days. 😀Amazing experience. Highly recommended.\u003c/p\u003e\n\n\u003cp\u003eThe important thing to understand is that \u003ccode\u003egit log\u003c/code\u003e shows you commits reachable from the history you’re currently looking at. If you reset your branch backwards, some commits may disappear from git log.\u003c/p\u003e\n\n\u003cp\u003eThat does not necessarily mean Git has immediately deleted them. Git also keeps a local log of movements of references such as \u003ccode\u003eHEAD\u003c/code\u003e. You can inspect that with:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight shell\"\u003e\u003ccode\u003egit reflog\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eYou may see something like:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight plaintext\"\u003e\u003ccode\u003ee35fa12 HEAD@{0}: reset: moving to HEAD~2\n821cd77 HEAD@{1}: commit: Add authentication\nf992ab1 HEAD@{2}: commit: Add login page\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eAha! There’s your missing commit.\u003c/p\u003e\n\n\u003cp\u003eNow you have several options. You could move the branch back to it:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight shell\"\u003e\u003ccode\u003egit reset \u003cspan class=\"nt\"\u003e--hard\u003c/span\u003e 821cd77\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eBut personally, if I’m already in panic-recovery mode, I prefer doing something safer first:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight shell\"\u003e\u003ccode\u003egit branch rescue 821cd77\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eNow the commit is reachable from a branch again and I can calmly inspect what happened without immediately rewriting anything else.\u003c/p\u003e\n\n\u003cp\u003eThe key difference is:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight plaintext\"\u003e\u003ccode\u003egit log\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eshows your visible commit history.\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight plaintext\"\u003e\u003ccode\u003egit reflog\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eshows where your local references, especially \u003ccode\u003eHEAD\u003c/code\u003e , have pointed recently.\u003c/p\u003e\n\n\u003cp\u003eThere is one important limitation, though. Reflog is not a magical backup of every character you’ve ever typed. If your changes were never committed, stashed, or otherwise stored as Git objects, \u003ccode\u003ereflog\u003c/code\u003e cannot magically resurrect them.\u003c/p\u003e\n\n\u003cp\u003eSo yes, if you worked for six hours without committing anything and then destroyed those changes... Well. Maybe this will teach you to commit more often next time. \u003c/p\u003e\n\n\n\u003chr\u003e\n\n\u003ch2\u003e\n \u003ca name=\"10-raw-git-revert-endraw-\" href=\"#10-raw-git-revert-endraw-\"\u003e\n \u003c/a\u003e\n 10. \u003ccode\u003egit revert\u003c/code\u003e\n\u003c/h2\u003e\n\n\u003cp\u003eAnd finally:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight shell\"\u003e\u003ccode\u003egit revert\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eImagine you release a commit to production. Or, in the slightly less hardcore version of this scenario, to some shared \u003ccode\u003edevelop\u003c/code\u003e branch.\u003c/p\u003e\n\n\u003cp\u003eSomething goes very wrong. Everything breaks. So what now? Do you run:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight shell\"\u003e\u003ccode\u003egit reset \u003cspan class=\"nt\"\u003e--hard\u003c/span\u003e\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eon the production branch?\u003c/p\u003e\n\n\u003cp\u003eDo you start performing an exorcism?\u003c/p\u003e\n\n\u003cp\u003eFortunately, no. The elegant way to undo a commit while preserving a clear record of what happened in your repository history is:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight shell\"\u003e\u003ccode\u003egit revert \u0026lt;commit-hash\u0026gt;\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eImagine your history looks like this:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight plaintext\"\u003e\u003ccode\u003eA---B---C\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eand \u003ccode\u003eC\u003c/code\u003e introduced the disaster.\u003c/p\u003e\n\n\u003cp\u003eYou run:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight shell\"\u003e\u003ccode\u003egit revert C\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eGit does \u003cstrong\u003enot\u003c/strong\u003e remove \u003ccode\u003eC\u003c/code\u003e.\u003c/p\u003e\n\n\u003cp\u003eInstead, it creates a new commit that applies the opposite changes:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight plaintext\"\u003e\u003ccode\u003eA---B---C---D\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eYou may end up with something like:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight plaintext\"\u003e\u003ccode\u003eC: Add new payment logic\nD: Revert \"Add new payment logic\"\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eThis is extremely useful on shared branches because you are not rewriting public history. Everyone can clearly see:\u003c/p\u003e\n\n\u003col\u003e\n\u003cli\u003ethe original change happened,\u003c/li\u003e\n\u003cli\u003eit caused trouble,\u003c/li\u003e\n\u003cli\u003eit was reverted.\u003c/li\u003e\n\u003c/ol\u003e\n\n\u003cp\u003eCompare that with resetting the branch and force-pushing it backwards, which rewrites history and can cause problems for everyone else working on it.\u003c/p\u003e\n\n\u003cp\u003eSo, as a general rule:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight plaintext\"\u003e\u003ccode\u003eShared branch + bad commit → revert\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eis usually much safer than:\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cdiv class=\"highlight js-code-highlight\"\u003e\n\u003cpre class=\"highlight plaintext\"\u003e\u003ccode\u003ereset + force push\n\u003c/code\u003e\u003c/pre\u003e\n\u003cdiv class=\"highlight__panel js-actions-panel\"\u003e\n\u003cdiv class=\"highlight__panel-action js-fullscreen-code-action\"\u003e\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"\u003e\u003ctitle\u003eEnter fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n \u003csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"\u003e\u003ctitle\u003eExit fullscreen mode\u003c/title\u003e\n \u003cpath d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\n\n\u003cp\u003eAnd that’s it!\u003c/p\u003e\n\n\u003cp\u003eAs I said at the beginning, if you use other intermediate Git commands that regularly save you time or save your ass, please share them in the comments. Usually the comments under my articles end up being much better than the article itself, which continues to make me very happy. \u003c/p\u003e\n\n\u003cp\u003eAlso, please note that last week’s article was a list. This week’s article is a list. And — spoiler alert — next week’s article will also be a list!\u003c/p\u003e\n\n\u003cp\u003eThis is not because I smelled clicks and decided to turn into BuzzFeed. It just somehow happened that way. 😅\u003c/p\u003e\n\n\u003cp\u003eI hope you learned something new. And if you didn’t, I hope it was at least fun to read. 😁\u003c/p\u003e\n\n","author":{"@type":"Person","name":"Sylwia Laskowska","url":"https://dev.to/sylwia-lask"},"datePublished":"2026-08-26T07:59:06Z","dateModified":"2026-08-26T07:59:06Z","url":"https://dev.to/sylwia-lask/10-git-commands-youll-wish-you-knew-earlier-4fcp","interactionStatistic":[{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":47},{"@type":"InteractionCounter","interactionType":"https://schema.org/LikeAction","userInteractionCount":108}],"comment":[{"@type":"Comment","@id":"#comment-1611607","text":"\u003cp\u003eThanks for the mention and great detail on using Git :D\u003c/p\u003e\n\n","author":{"@type":"Person","name":"FrancisTRᴅᴇᴠ (っ◔◡◔)っ","url":"https://dev.to/francistrdev"},"datePublished":"2026-08-26T14:40:53Z","dateModified":"2026-08-26T14:40:53Z","url":"https://dev.to/francistrdev/comment/3di0n","interactionStatistic":[{"@type":"InteractionCounter","interactionType":"https://schema.org/LikeAction","userInteractionCount":2}],"comment":[{"@type":"Comment","@id":"#comment-1611619","text":"\u003cp\u003eHaha never enough of Git 🙂\u003c/p\u003e\n\n","author":{"@type":"Person","name":"Sylwia Laskowska","url":"https://dev.to/sylwia-lask"},"datePublished":"2026-08-26T14:53:00Z","dateModified":"2026-08-26T14:53:00Z","url":"https://dev.to/sylwia-lask/comment/3di19","interactionStatistic":[{"@type":"InteractionCounter","interactionType":"https://schema.org/LikeAction","userInteractionCount":2}],"parentItem":{"@type":"Comment","@id":"#comment-1611607"}}]},{"@type":"Comment","@id":"#comment-1611352","text":"\u003cp\u003eA best how to use git short document!\u003c/p\u003e\n\n","author":{"@type":"Person","name":"Peter Vivo","url":"https://dev.to/pengeszikra"},"datePublished":"2026-08-26T09:13:23Z","dateModified":"2026-08-26T09:13:23Z","url":"https://dev.to/pengeszikra/comment/3dhh2","interactionStatistic":[{"@type":"InteractionCounter","interactionType":"https://schema.org/LikeAction","userInteractionCount":2}],"comment":[{"@type":"Comment","@id":"#comment-1611364","text":"\u003cp\u003eOoooh, thank you so much! ☺️ Now I can just send this article to juniors instead of explaining all of this on a call every time. 😂\u003c/p\u003e\n\n","author":{"@type":"Person","name":"Sylwia Laskowska","url":"https://dev.to/sylwia-lask"},"datePublished":"2026-08-26T09:35:23Z","dateModified":"2026-08-26T09:35:23Z","url":"https://dev.to/sylwia-lask/comment/3dhhe","interactionStatistic":[{"@type":"InteractionCounter","interactionType":"https://schema.org/LikeAction","userInteractionCount":2}],"parentItem":{"@type":"Comment","@id":"#comment-1611352"}}]},{"@type":"Comment","@id":"#comment-1611386","text":"\u003cp\u003eHi Sylwia! 😂\u003c/p\u003e\n\n\u003cp\u003e\u003ccode\u003egit reflog\u003c/code\u003e is basically Git’s emergency contact. You hope you never need it, but the moment you accidentally nuke two days of work, suddenly it’s your best friend.\u003c/p\u003e\n\n\u003cp\u003eNow I’m curious: which Git command has saved you from the biggest disaster so far? 😄\u003c/p\u003e\n\n","author":{"@type":"Person","name":"buildbasekit","url":"https://dev.to/buildbasekit"},"datePublished":"2026-08-26T10:04:12Z","dateModified":"2026-08-26T10:04:12Z","url":"https://dev.to/buildbasekit/comment/3dhia","interactionStatistic":[{"@type":"InteractionCounter","interactionType":"https://schema.org/LikeAction","userInteractionCount":3}],"comment":[{"@type":"Comment","@id":"#comment-1611398","text":"\u003cp\u003eHaha, that’s a good question! 😄 I’d say \u003ccode\u003egit revert\u003c/code\u003e has definitely saved me from the biggest disasters. \u003ccode\u003egit reflog\u003c/code\u003e can save your work, sure, but \u003ccode\u003egit revert\u003c/code\u003e can save production. 😂\u003c/p\u003e\n\n","author":{"@type":"Person","name":"Sylwia Laskowska","url":"https://dev.to/sylwia-lask"},"datePublished":"2026-08-26T10:15:06Z","dateModified":"2026-08-26T10:15:06Z","url":"https://dev.to/sylwia-lask/comment/3dhim","interactionStatistic":[{"@type":"InteractionCounter","interactionType":"https://schema.org/LikeAction","userInteractionCount":3}],"parentItem":{"@type":"Comment","@id":"#comment-1611386"}}]},{"@type":"Comment","@id":"#comment-1611613","text":"\u003cp\u003eGit commands are basic, but really important for every developer. \u003cbr\u003e\nI think this will be a valuable article for many people! 😸\u003c/p\u003e\n\n\u003cp\u003eI use aliases in my \u003ccode\u003e.zshrc\u003c/code\u003e, for example, \u003ccode\u003egc=\"git commit -S\"\u003c/code\u003e.\u003c/p\u003e\n\n\u003cp\u003eIt makes my daily Git workflow a little bit faster.\u003cbr\u003e\nDo you have any similar tricks or customizations in your setup? I'm curious! 😸\u003c/p\u003e\n\n","author":{"@type":"Person","name":"nyaomaru","url":"https://dev.to/nyaomaru"},"datePublished":"2026-08-26T14:46:41Z","dateModified":"2026-08-26T14:46:41Z","url":"https://dev.to/nyaomaru/comment/3di13","interactionStatistic":[{"@type":"InteractionCounter","interactionType":"https://schema.org/LikeAction","userInteractionCount":2}],"comment":[{"@type":"Comment","@id":"#comment-1611863","text":"\u003cp\u003eHaha, you know what? I actually don’t! 😄 I know about Git aliases, but I prefer typing the commands manually so I don’t forget them, partly because then I can recite them from memory when explaining Git to juniors. 😂\u003c/p\u003e\n\n\u003cp\u003eBut we do have a very funny Polish repo with Git aliases called \u003cstrong\u003e“git kurwa”\u003c/strong\u003e (“kurwa” is a Polish swear word 😅). So apparently we’ve found a very Polish solution to Git frustration. 😂\u003c/p\u003e\n\n","author":{"@type":"Person","name":"Sylwia Laskowska","url":"https://dev.to/sylwia-lask"},"datePublished":"2026-08-26T19:40:31Z","dateModified":"2026-08-26T19:40:31Z","url":"https://dev.to/sylwia-lask/comment/3diaj","interactionStatistic":[{"@type":"InteractionCounter","interactionType":"https://schema.org/LikeAction","userInteractionCount":2}],"parentItem":{"@type":"Comment","@id":"#comment-1611613"}}]},{"@type":"Comment","@id":"#comment-1611693","text":"\u003cp\u003eThe merge vs rebase section is the one that finally made things click for me, I'd been using both without really understanding why I was choosing one over the other. The diagram of commits being replayed with new hashes is such a cleaner way to explain why rebasing shared history is risky.\u003c/p\u003e\n\n\u003cp\u003egit stash is probably the one I reach for most often in my day to day, that moment where you're halfway through something and a bug report lands and you just need to put everything down cleanly without committing a mess.\u003c/p\u003e\n\n\u003cp\u003eOne I'd add at this level: git log --oneline --graph --all — not a command that does anything dramatic, but seeing the branch structure visually in the terminal helped me understand what merge and rebase were actually doing to my history way faster than any explanation did.\u003c/p\u003e\n\n","author":{"@type":"Person","name":"Gamya ","url":"https://dev.to/gamya_m"},"datePublished":"2026-08-26T15:55:29Z","dateModified":"2026-08-26T15:55:29Z","url":"https://dev.to/gamya_m/comment/3di45","interactionStatistic":[{"@type":"InteractionCounter","interactionType":"https://schema.org/LikeAction","userInteractionCount":2}],"comment":[{"@type":"Comment","@id":"#comment-1611867","text":"\u003cp\u003eThanks so much for the comment! 😄 And yes, --graph is great!\u003c/p\u003e\n\n\u003cp\u003eI have to admit that even though I type probably 90% of my Git commands manually, I still like using SourceTree, pretty much exclusively to look at the branch and commit tree. 😂 I’m definitely a visual learner, so being able to actually see the history makes everything much easier for me.\u003c/p\u003e\n\n","author":{"@type":"Person","name":"Sylwia Laskowska","url":"https://dev.to/sylwia-lask"},"datePublished":"2026-08-26T19:42:57Z","dateModified":"2026-08-26T19:42:57Z","url":"https://dev.to/sylwia-lask/comment/3dian","interactionStatistic":[{"@type":"InteractionCounter","interactionType":"https://schema.org/LikeAction","userInteractionCount":1}],"parentItem":{"@type":"Comment","@id":"#comment-1611693"}}]},{"@type":"Comment","@id":"#comment-1612156","text":"\u003cp\u003egit reflog deserves more attention than it usually gets. Most Git commands are about changing the state of your repository, while reflog gives you a way to understand how you got there when something goes wrong. That makes it less of a daily workflow command and more of a recovery tool—and probably one of the best safety nets to learn before you actually need it.\u003c/p\u003e\n\n","author":{"@type":"Person","name":"Glen Allen","url":"https://dev.to/glenallen"},"datePublished":"2026-08-27T04:42:52Z","dateModified":"2026-08-27T04:42:52Z","url":"https://dev.to/glenallen/comment/3dim0","interactionStatistic":[{"@type":"InteractionCounter","interactionType":"https://schema.org/LikeAction","userInteractionCount":2}],"comment":[{"@type":"Comment","@id":"#comment-1612282","text":"\u003cp\u003eExactly! Especially when you accidentally click the wrong thing somewhere, or when a rebase goes very, very wrong. 😂 That’s when git reflog suddenly becomes your best friend.\u003c/p\u003e\n\n","author":{"@type":"Person","name":"Sylwia Laskowska","url":"https://dev.to/sylwia-lask"},"datePublished":"2026-08-27T07:38:39Z","dateModified":"2026-08-27T07:38:39Z","url":"https://dev.to/sylwia-lask/comment/3dj0m","interactionStatistic":[{"@type":"InteractionCounter","interactionType":"https://schema.org/LikeAction","userInteractionCount":1}],"parentItem":{"@type":"Comment","@id":"#comment-1612156"}},{"@type":"Comment","@id":"#comment-1612443","text":"\u003cp\u003eGood framing, but worth to remember reflog lives inside .git, so it saves you only from yourself. When my SSD died the reflog died in same second, and what actually brought the thing back was a 13MB snapshot sitting on another machine. Local safety net and off machine copy are two different things, and most people have only first one.\u003c/p\u003e\n\n","author":{"@type":"Person","name":"Artjoms Stukans","url":"https://dev.to/artyomsv"},"datePublished":"2026-08-27T11:24:29Z","dateModified":"2026-08-27T11:24:29Z","url":"https://dev.to/artyomsv/comment/3dj71","interactionStatistic":[{"@type":"InteractionCounter","interactionType":"https://schema.org/LikeAction","userInteractionCount":1}],"parentItem":{"@type":"Comment","@id":"#comment-1612156"}}]},{"@type":"Comment","@id":"#comment-1611355","text":"\u003cp\u003eYou're making me feel old! When I was a junior, Git didn't even exist. I started back in the day with Visual SourceSafe 6.0, then moved to SVN (good old TortoiseSVN), until Microsoft eventually pushed everyone to TFS.\u003c/p\u003e\n\n\u003cp\u003eI only really made the jump to Git around 2019 when I joined Bloomberg, and only switched my personal projects to it about two years ago after sticking with the MS ecosystem for ages.\u003c/p\u003e\n\n\u003cp\u003eGreat list of commands, by the way. My favorite: cherry-pick!\u003c/p\u003e\n\n","author":{"@type":"Person","name":"Sandro Garcia","url":"https://dev.to/sandrog"},"datePublished":"2026-08-26T09:21:08Z","dateModified":"2026-08-26T09:21:08Z","url":"https://dev.to/sandrog/comment/3dhh5","interactionStatistic":[{"@type":"InteractionCounter","interactionType":"https://schema.org/LikeAction","userInteractionCount":2}],"comment":[{"@type":"Comment","@id":"#comment-1611368","text":"\u003cp\u003eThank you so much, Sandro! And yes, that’s true, especially with older projects, SVN managed to stick around for years and years.\u003c/p\u003e\n\n\u003cp\u003eI’ve actually worked with Git since the very beginning of my career, but here’s the plot twist: I used TortoiseGit. 😂 As far as I remember, it was basically the Git-enabled cousin of TortoiseSVN. So apparently our Git histories crossed paths after all! 😄\u003c/p\u003e\n\n","author":{"@type":"Person","name":"Sylwia Laskowska","url":"https://dev.to/sylwia-lask"},"datePublished":"2026-08-26T09:38:33Z","dateModified":"2026-08-26T09:38:33Z","url":"https://dev.to/sylwia-lask/comment/3dhhi","interactionStatistic":[{"@type":"InteractionCounter","interactionType":"https://schema.org/LikeAction","userInteractionCount":2}],"parentItem":{"@type":"Comment","@id":"#comment-1611355"}}]},{"@type":"Comment","@id":"#comment-1612052","text":"\u003cp\u003eAfter 15 years of dealing with git, I learned \u003ccode\u003epush --force-with-lease\u003c/code\u003e, wow\u003c/p\u003e\n\n","author":{"@type":"Person","name":"Aliaksei Zelianouski","url":"https://dev.to/hiper2d"},"datePublished":"2026-08-27T01:13:29Z","dateModified":"2026-08-27T01:13:29Z","url":"https://dev.to/hiper2d/comment/3dii0","interactionStatistic":[{"@type":"InteractionCounter","interactionType":"https://schema.org/LikeAction","userInteractionCount":2}],"comment":[{"@type":"Comment","@id":"#comment-1612274","text":"\u003cp\u003eHaha, that’s exactly the beauty of these lists! 😄 You can be coding for 15 years, know 90% of the stuff on the list, and there’s still that one command that makes you go, “Wait, WHAT?!” 😂\u003c/p\u003e\n\n","author":{"@type":"Person","name":"Sylwia Laskowska","url":"https://dev.to/sylwia-lask"},"datePublished":"2026-08-27T07:33:59Z","dateModified":"2026-08-27T07:33:59Z","url":"https://dev.to/sylwia-lask/comment/3dj0e","interactionStatistic":[{"@type":"InteractionCounter","interactionType":"https://schema.org/LikeAction","userInteractionCount":1}],"parentItem":{"@type":"Comment","@id":"#comment-1612052"}}]},{"@type":"Comment","@id":"#comment-1611682","text":"\u003cp\u003eGreat distinction between learning Git basics and learning the commands that actually make day-to-day development easier. The best Git lessons usually come from experienced developers sharing the small workflows and commands they rely on repeatedly. Looking forward to the rest of the list.\u003c/p\u003e\n\n","author":{"@type":"Person","name":"jacob foster","url":"https://dev.to/jacobfoster21"},"datePublished":"2026-08-26T15:47:55Z","dateModified":"2026-08-26T15:47:55Z","url":"https://dev.to/jacobfoster21/comment/3di3k","interactionStatistic":[{"@type":"InteractionCounter","interactionType":"https://schema.org/LikeAction","userInteractionCount":2}],"comment":[{"@type":"Comment","@id":"#comment-1611873","text":"\u003cp\u003eThank you so much! And yes, exactly! In the beginning, you can absolutely survive without these commands, but they quickly become pretty essential if you don’t want to lose your mind working with Git every day. 😂\u003c/p\u003e\n\n","author":{"@type":"Person","name":"Sylwia Laskowska","url":"https://dev.to/sylwia-lask"},"datePublished":"2026-08-26T19:49:34Z","dateModified":"2026-08-26T19:49:34Z","url":"https://dev.to/sylwia-lask/comment/3dib3","interactionStatistic":[{"@type":"InteractionCounter","interactionType":"https://schema.org/LikeAction","userInteractionCount":1}],"parentItem":{"@type":"Comment","@id":"#comment-1611682"}}]},{"@type":"Comment","@id":"#comment-1611722","text":"\u003cp\u003eThe \u003ccode\u003egit rebase -i\u003c/code\u003e + \u003ccode\u003egit reflog\u003c/code\u003e combo saved me last week after I force-pushed over a teammate's commit — reflog found the lost SHA in about 10 seconds. One command I'd add to this list: \u003ccode\u003egit log -S\u0026lt;string\u0026gt;\u003c/code\u003e (pickaxe search) — it finds the commit that \u003cem\u003eintroduced or removed\u003c/em\u003e a specific string, which is how I tracked down who silently dropped an env var check three months ago. Grepping history by diff content beats reading 500 commit subjects.\u003c/p\u003e\n\n\u003cp\u003eDo you find interactive rebase actually safe to teach juniors, or do you steer them toward \u003ccode\u003egit merge --no-ff\u003c/code\u003e until they've internalized reflog recovery first?\u003c/p\u003e\n\n","author":{"@type":"Person","name":"Niuniu Ox","url":"https://dev.to/byteox2"},"datePublished":"2026-08-26T16:32:12Z","dateModified":"2026-08-26T16:32:12Z","url":"https://dev.to/byteox2/comment/3di58","interactionStatistic":[{"@type":"InteractionCounter","interactionType":"https://schema.org/LikeAction","userInteractionCount":2}],"comment":[{"@type":"Comment","@id":"#comment-1611877","text":"\u003cp\u003eOh, that git log -S tip is great! 😄 I’d probably have reached for git blame and started digging from there, so I’m definitely keeping this one in mind!\u003c/p\u003e\n\n\u003cp\u003eAs for interactive rebase, juniors usually come in already knowing how to work with merges, so I tend to introduce rebase fairly early. Of course, how quickly they actually start using it confidently varies. 😅 git commit --amend, on the other hand, they pick up almost immediately. 😂\u003c/p\u003e\n\n\u003cp\u003eAlthough I guess I should be speaking in the past tense here, I haven’t had many juniors around lately. :(\u003c/p\u003e\n\n","author":{"@type":"Person","name":"Sylwia Laskowska","url":"https://dev.to/sylwia-lask"},"datePublished":"2026-08-26T19:57:35Z","dateModified":"2026-08-26T19:57:35Z","url":"https://dev.to/sylwia-lask/comment/3dib7","interactionStatistic":[{"@type":"InteractionCounter","interactionType":"https://schema.org/LikeAction","userInteractionCount":1}],"parentItem":{"@type":"Comment","@id":"#comment-1611722"}}]}]}} if (/Twitter for (iPhone|iPad|Android)/i.test(navigator.userAgent)) { document.documentElement.classList.add('is-twitter-in-app'); } Add reaction Like Unicorn Exploding Head Raised Hands Fire Jump to Comments Save Boost More... Copy link Copy link Copied to Clipboard Share to X Share to LinkedIn Share to Facebook Share to Mastodon Share Post via... Report Abuse try { if(localStorage) { let currentUser = localStorage.getItem('current_user'); if (currentUser) { currentUser = JSON.parse(currentUser); if (currentUser.id === 3535771) { document.getElementById('article-show-container').classList.add('current-user-is-article-author'); } } } } catch (e) { console.error(e); } Sylwia Laskowska Posted on Aug 26 10 Git Commands You’ll Wish You Knew Earlier # git # programming # productivity # beginners Targeted at devs past the basics Do you know Git? Of course you do! Today, I’ve got a few of my favorite Git commands for you. When I was a junior developer, my tech lead taught me most of them (hi Wojtek, if you’re reading this 👋) and later, I started teaching the same commands to my own junior and mid-level developers. I’ve actually been meaning to write this article for months. But you know how it is. It’s evergreen content, it requires a bit of work, and meanwhile I kept coming up with other ideas, so I kept postponing it. What finally motivated me was @francistrdev , who recently published his own article about Git commands. My article will be a little different, though. If you’re completely new to Git and still learning the basics, check out Francis’s Git Gud! article first. But if add , commit , pull , and push are already second nature to you, this article is for you. These are, let’s say, intermediate-level commands. Useful ones. The kind you actually need at work, but not yet senior-level Git magic like: Type three lines into your terminal and a spaceship will appear in your repository. If you have other useful commands at this level, please share them in the comments! BTW, if you feel like it, you can also follow me on Instagram! I’m planning to post what could grandly be called “dev lifestyle” content there. 😅 I have four conferences coming up this fall, for example, so expect some behind-the-scenes photos from my little tour around Europe. I only have a handful of followers there so far and absolutely no idea what this experiment will turn into, but here you go: @sylwia.lask All right, let’s start. 1. & 2. git merge vs git rebase Haha, first point and we already have two commands. The reason I’m putting them together is that a lot of developers, even experienced ones, treat merge and rebase almost interchangeably. And sure, their high-level purpose is similar: you want to integrate the history of one branch into another. Very often that means updating your feature branch with changes from main , develop , or another feature branch. But the way they do it is quite different. Imagine you have this: A---B---C main \ D---E feature Enter fullscreen mode Exit fullscreen mode You’ve been happily working on your feature branch, while someone else added commit C to main . Now you want to bring those changes into your branch. Merge If you run: git merge main Enter fullscreen mode Exit fullscreen mode while you’re on feature , Git combines both histories. You usually end up with something like this: A---B---C------M \ / D---E--- Enter fullscreen mode Exit fullscreen mode M is a merge commit. The original history stays intact. Git remembers that your feature branch diverged from main , both branches evolved independently for a while, and then they were joined together. This can be a good thing because it preserves the real history of what happened. The downside is that if you merge main into your feature branch over and over again, your history can eventually start looking like spaghetti. Rebase Now let’s say instead you run: git rebase main Enter fullscreen mode Exit fullscreen mode Git takes commits D and E , temporarily removes them, moves your branch onto the latest main , and then reapplies your commits on top. You get: A---B---C---D'---E' Enter fullscreen mode Exit fullscreen mode Much cleaner. But notice the apostrophes. D' and E' are not technically the same commits as D and E . Git created new commits with new hashes. That means rebase rewrites history . This is why a very useful rule of thumb is: Rebase your own work. Be careful rebasing shared history. If you’re working alone on a feature branch, rebasing it is usually perfectly fine. If three other developers have already based their work on your commits, rebasing those commits can make everyone’s life considerably more exciting. And not in a good way. And what about conflicts? Both merge and rebase can result in conflicts. With a merge, Git tries to combine the two histories in one operation. You resolve the conflicting files, stage them: git add . Enter fullscreen mode Exit fullscreen mode and then continue: git merge --continue Enter fullscreen mode Exit fullscreen mode With rebase, things can be slightly more annoying because Git reapplies your commits one by one. This means you may resolve a conflict, continue the rebase... git add . git rebase --continue Enter fullscreen mode Exit fullscreen mode ...and then get another conflict in the next commit. And another one. And another one. At which point you start questioning every career decision that led you here. 😅 But there’s also a small bonus. If you completely mess things up and just want to stop the entire circus, you can do: git merge --abort Enter fullscreen mode Exit fullscreen mode or: git rebase --abort Enter fullscreen mode Exit fullscreen mode Git will try to return you to the state from before the merge or rebase started. Extremely useful feature. 😁 3. git commit --amend This is one of those commands I learned to love very quickly as a junior. Imagine you’ve just created a beautiful, perfectly round little commit. Then you look at the code and notice you forgot something.In my case, it was usually: console . log ( " WTF " ); Enter fullscreen mode Exit fullscreen mode You now have two options. Option one: make another glorious commit: Remove console log Enter fullscreen mode Exit fullscreen mode Which, let’s be honest, is not exactly the pinnacle of Git history aesthetics. Or you can simply add the forgotten change to the previous commit. For example: git add forgotten-file.ts git commit --amend --no-edit Enter fullscreen mode Exit fullscreen mode --no-edit means: Add these changes to the previous commit, but keep the existing commit message. If you want to change the commit message as well, just run: git commit --amend Enter fullscreen mode Exit fullscreen mode Git will open your configured editor and let you modify it. There is one important detail here. amend doesn’t literally edit the existing commit. It creates a new commit containing the updated contents. And because commit hashes depend on the contents and metadata of the commit, the hash changes. If you’re working locally and haven’t pushed the branch anywhere yet, no problem. But if the branch already exists on remote, your local history no longer matches the remote history. So when you try: git push Enter fullscreen mode Exit fullscreen mode you’ll probably get something like: rejected (non-fast-forward) Enter fullscreen mode Exit fullscreen mode Now, if you are absolutely sure nobody else is working on that branch, you could technically do: git push --force Enter fullscreen mode Exit fullscreen mode But what if you’re not sure? And this brings us very smoothly to the next point. 4. git push --force-with-lease After a rebase, amend, interactive rebase, squash, or anything else that rewrites your commits, your local branch history may no longer match the version stored on remote. You can solve that with: git push --force Enter fullscreen mode Exit fullscreen mode But --force is basically saying: My local version is the truth. Replace whatever is on remote with this. If someone pushed something to that branch in the meantime, you can overwrite their work. They may get angry. And rightly so. 😏 A much safer option is: git push --force-with-lease Enter fullscreen mode Exit fullscreen mode In simplified terms, this tells Git: Force-push my version, but only if the remote branch still looks the way I expect it to. If the remote branch changed since the state your local Git knows about, for example because someone else pushed new commits, Git refuses the push instead of blindly overwriting them. So instead of destroying someone’s afternoon, you get an error. I generally recommend: --force-with-lease Enter fullscreen mode Exit fullscreen mode over: --force Enter fullscreen mode Exit fullscreen mode whenever possible. 5. git rebase -i For me, this is a very important command. Almost the king of Git. xDDDD Interactive rebase lets you do almost anything you want with your recent commits. In other words, you can commit every single line individually, change everything ten times, create commits like: Add validation Fix validation Actually fix validation Fix validation again Remove console.log Please work now Enter fullscreen mode Exit fullscreen mode and then later turn the whole mess into an elegant Git history. Let’s say you want to edit your last five commits. You run: git rebase -i HEAD~5 Enter fullscreen mode Exit fullscreen mode Git opens your configured editor — Vim, Nano, VS Code, or whatever you use — and shows something similar to: pick a111111 Add login form pick b222222 Add validation pick c333333 Fix typo pick d444444 Fix validation pick e555555 Remove debug log Enter fullscreen mode Exit fullscreen mode Now comes the fun part. You can replace pick with different commands. pick Keep the commit exactly as it is. pick a111111 Add login form Enter fullscreen mode Exit fullscreen mode reword Keep the commit contents, but change its message. reword a111111 Add beautiful login form Enter fullscreen mode Exit fullscreen mode edit Pause the rebase at that commit and let you modify it. Useful if you want to change the actual contents of an older commit. squash Combine the commit with the one before it. For example: pick a111111 Add login form squash b222222 Add validation squash c333333 Fix validation Enter fullscreen mode Exit fullscreen mode Git turns those commits into one and lets you edit the final commit message. So instead of: Add login form Add validation Fix validation Enter fullscreen mode Exit fullscreen mode you can end up with: Add login form with validation Enter fullscreen mode Exit fullscreen mode Beautiful. Round. Perfect. fixup fixup is similar to squash , but it throws away the commit message of the fixup commit. For example: pick a111111 Add login form fixup b222222 Fix typo fixup c333333 Remove console.log Enter fullscreen mode Exit fullscreen mode You probably don’t care about preserving the historical significance of: Remove console.log Enter fullscreen mode Exit fullscreen mode So fixup is perfect here. drop Remove the commit completely. drop c333333 Terrible idea Enter fullscreen mode Exit fullscreen mode Goodbye. Of course, there are different schools of thought about how much you should clean up your commits. Some senior developers say that submitting a nicely cleaned-up commit history for review is simply good manners. Others do not care in the slightest and think it’s unnecessary because GitHub, GitLab, or whatever platform you use can simply squash everything when merging the PR anyway. But!!! What if you don’t want to click Squash and merge ? What if your feature logically contains two commits and you actually want to preserve both? That happens. So whether you use interactive rebase once a week or once every six months, I still think it’s worth knowing the king: git rebase -i Enter fullscreen mode Exit fullscreen mode 6. git stash This one comes in handy very often. You start working on a nice little feature. Or, these days, Kiro or Claude Code is working very hard while you watch. Suddenly someone reports a production bug. Unfortunately, you now have to temporarily abandon your beautiful feature and switch to something else. The problem is that your current work is completely unfinished. You have debug logs everywhere, half the files are modified, the project doesn’t even build, and you definitely don’t want to commit this mess. Although, of course, now you know about amend , so you could eventually clean it up. But there’s a better solution: git stash Enter fullscreen mode Exit fullscreen mode Git temporarily stores your uncommitted changes and returns your working directory to a clean state. Now you can switch branches: git switch main Enter fullscreen mode Exit fullscreen mode fix your production disaster, and later come back. One important detail: by default, git stash stashes tracked files, but not new untracked files. If you also want to include newly created files, use: git stash -u Enter fullscreen mode Exit fullscreen mode or, even better, give your stash a useful name: git stash push -u -m "WIP login feature" Enter fullscreen mode Exit fullscreen mode Because once you have several stashes named basically “WIP”, future you will hate present you. git stash list To see all your stashes: git stash list Enter fullscreen mode Exit fullscreen mode You might get: stash@{0}: On feature/login: WIP login feature stash@{1}: On feature/cart: experiment Enter fullscreen mode Exit fullscreen mode git stash show To see what a particular stash contains: git stash show stash@ { 0 } Enter fullscreen mode Exit fullscreen mode And if you want the full diff: git stash show -p stash@ { 0 } Enter fullscreen mode Exit fullscreen mode git stash apply To restore a stash: git stash apply stash@ { 0 } Enter fullscreen mode Exit fullscreen mode The changes are restored, but the stash remains in the list. git stash pop You can also use: git stash pop Enter fullscreen mode Exit fullscreen mode This applies the stash and, if successful, removes it from the stash list. So, roughly: apply = restore pop = restore + remove from stash Enter fullscreen mode Exit fullscreen mode Very simple, very useful. 7. git cherry-pick I have to admit this is one of the intermediate Git commands I use most often. Imagine there’s one specific commit on another branch that you want in your current branch. You don’t want to merge the whole branch. You don’t want to rebase onto it. You literally need one thing. For example, in my project recently, I needed a commit containing configuration for newly created environments. Perfect use case. You simply run: git cherry-pick <commit-hash> Enter fullscreen mode Exit fullscreen mode For example: git cherry-pick a1b2c3d Enter fullscreen mode Exit fullscreen mode Git takes the changes introduced by that commit and applies them to your current branch. Important detail: it creates a new commit . So the resulting commit contains essentially the same changes, but it gets a new hash. Imagine this history: main A---B---C feature \ D---E---F Enter fullscreen mode Exit fullscreen mode You’re on main , but you only want E . After: git cherry-pick E Enter fullscreen mode Exit fullscreen mode you get something like: A---B---C---E' Enter fullscreen mode Exit fullscreen mode Simple. But I’ll admit that, being a lazy creature, I use cherry-pick in slightly less noble ways too. Sometimes something gets completely messed up on my branch. The rebase goes badly, the history looks suspicious, conflicts start multiplying, and after a while I decide: I'll create a completely new branch from the correct place at the top of the tree. 😅 And because — thanks to the previous commands ☺️ — my commits are already nice and round, I simply cherry-pick them one by one onto the new branch. I’m sure some Git pro is currently shaking their head at me, but let me put it this way: It works for me. 😀 8. git reset --soft , --mixed , --hard Three ways of moving back in history, each with a different answer to the question: What should happen to my changes? Because how many times do we start working on something, write some code, and then realize: Nope. This whole idea was bad. Let’s go back. The easiest way to understand reset is to think about three layers: Commit history Staging area Working directory Enter fullscreen mode Exit fullscreen mode Now we have three increasingly dramatic levels of reset. And every next one has greater potential to cause a small heart attack if you use the wrong one. git reset --soft Let’s say you want to undo the last commit: git reset --soft HEAD~1 Enter fullscreen mode Exit fullscreen mode Git moves HEAD back by one commit, but all the changes from the removed commit remain staged . So if your history was: A---B Enter fullscreen mode Exit fullscreen mode after the reset, your branch points to: A Enter fullscreen mode Exit fullscreen mode but the changes introduced by B are still ready to commit. This is useful when you committed too early and want to recreate the commit differently. git reset --mixed Now: git reset --mixed HEAD~1 Enter fullscreen mode Exit fullscreen mode or simply: git reset HEAD~1 Enter fullscreen mode Exit fullscreen mode because --mixed is the default. Again, Git moves back one commit. But this time the changes are left in your working directory unstaged . So nothing disappears from your files, but you need to git add things again before committing. git reset --hard And now we enter the danger zone: git reset --hard HEAD~1 Enter fullscreen mode Exit fullscreen mode This moves HEAD back and updates both the staging area and working directory to match that commit. In other words, the changes disappear from your files too. So: --soft → keep changes staged --mixed → keep changes unstaged --hard → discard changes from the working tree Enter fullscreen mode Exit fullscreen mode Use the last one with some awareness of what you’re doing. But what if you go one step too far and accidentally delete something you absolutely did not mean to delete? And that brings us to... 9. git reflog A command I use very rarely. But oh, how many times it has saved my ass. For example, when I once ran git reset --hard and instead of removing my last changes, I basically removed the branch I had been working on for two days. 😀Amazing experience. Highly recommended. The important thing to understand is that git log shows you commits reachable from the history you’re currently looking at. If you reset your branch backwards, some commits may disappear from git log. That does not necessarily mean Git has immediately deleted them. Git also keeps a local log of movements of references such as HEAD . You can inspect that with: git reflog Enter fullscreen mode Exit fullscreen mode You may see something like: e35fa12 HEAD@{0}: reset: moving to HEAD~2 821cd77 HEAD@{1}: commit: Add authentication f992ab1 HEAD@{2}: commit: Add login page Enter fullscreen mode Exit fullscreen mode Aha! There’s your missing commit. Now you have several options. You could move the branch back to it: git reset --hard 821cd77 Enter fullscreen mode Exit fullscreen mode But personally, if I’m already in panic-recovery mode, I prefer doing something safer first: git branch rescue 821cd77 Enter fullscreen mode Exit fullscreen mode Now the commit is reachable from a branch again and I can calmly inspect what happened without immediately rewriting anything else. The key difference is: git log Enter fullscreen mode Exit fullscreen mode shows your visible commit history. git reflog Enter fullscreen mode Exit fullscreen mode shows where your local references, especially HEAD , have pointed recently. There is one important limitation, though. Reflog is not a magical backup of every character you’ve ever typed. If your changes were never committed, stashed, or otherwise stored as Git objects, reflog cannot magically resurrect them. So yes, if you worked for six hours without committing anything and then destroyed those changes... Well. Maybe this will teach you to commit more often next time. 10. git revert And finally: git revert Enter fullscreen mode Exit fullscreen mode Imagine you release a commit to production. Or, in the slightly less hardcore version of this scenario, to some shared develop branch. Something goes very wrong. Everything breaks. So what now? Do you run: git reset --hard Enter fullscreen mode Exit fullscreen mode on the production branch? Do you start performing an exorcism? Fortunately, no. The elegant way to undo a commit while preserving a clear record of what happened in your repository history is: git revert <commit-hash> Enter fullscreen mode Exit fullscreen mode Imagine your history looks like this: A---B---C Enter fullscreen mode Exit fullscreen mode and C introduced the disaster. You run: git revert C Enter fullscreen mode Exit fullscreen mode Git does not remove C . Instead, it creates a new commit that applies the opposite changes: A---B---C---D Enter fullscreen mode Exit fullscreen mode You may end up with something like: C: Add new payment logic D: Revert "Add new payment logic" Enter fullscreen mode Exit fullscreen mode This is extremely useful on shared branches because you are not rewriting public history. Everyone can clearly see: the original change happened, it caused trouble, it was reverted. Compare that with resetting the branch and force-pushing it backwards, which rewrites history and can cause problems for everyone else working on it. So, as a general rule: Shared branch + bad commit → revert Enter fullscreen mode Exit fullscreen mode is usually much safer than: reset + force push Enter fullscreen mode Exit fullscreen mode And that’s it! As I said at the beginning, if you use other intermediate Git commands that regularly save you time or save your ass, please share them in the comments. Usually the comments under my articles end up being much better than the article itself, which continues to make me very happy. Also, please note that last week’s article was a list. This week’s article is a list. And — spoiler alert — next week’s article will also be a list! This is not because I smelled clicks and decided to turn into BuzzFeed. It just somehow happened that way. 😅 I hope you learned something new. And if you didn’t, I hope it was at least fun to read. 😁 Top comments (47) Subscribe Personal Trusted User Create template Templates let you quickly answer FAQs or store snippets for re-use. Submit Preview Dismiss Collapse Expand FrancisTRᴅᴇᴠ (っ◔◡◔)っ FrancisTRᴅᴇᴠ (っ◔◡◔)っ FrancisTRᴅᴇᴠ (っ◔◡◔)っ Follow 📚 𝗙𝘂𝗹𝗹-𝗦𝘁𝗮𝗰𝗸 𝗗𝗲𝘃𝗲𝗹𝗼𝗽𝗲𝗿 📚 🚀 𝗗𝗘𝗩 𝗖𝗼𝗺𝗺𝘂𝗻𝗶𝘁𝘆 𝗠𝗼𝗱𝗲𝗿𝗮𝘁𝗼𝗿 🚀 ༼ つ ◕_◕ ༽つ🍰🍔🍕 ₍₍⚞(˶>ᗜ<˶)⚟⁾⁾ "ᴀ ꜱᴍᴏᴏᴛʜ ꜱᴇᴀ ɴᴇᴠᴇʀ ᴍᴀᴅᴇ ᴀ ꜱᴋɪʟʟᴇᴅ ꜱᴀɪʟᴏʀ" - ꜰʀᴀɴᴋʟɪɴ ᴅ. ʀᴏᴏꜱᴇᴠᴇʟᴛ Location United States Education 🎓 Master's in Software Engineering 🎓 Pronouns He/Him Work ☕ Senior Full-Stack Developer at CALEC ☕ Joined Jan 14, 2026 • Aug 26 Dropdown menu Copy link Hide Thanks for the mention and great detail on using Git :D Like comment: Like comment: 2 likes Like Comment button Reply Collapse Expand Sylwia Laskowska Sylwia Laskowska Sylwia Laskowska Follow Software dev • 10+ yrs of code & caffeine ☕ • Sci-fi fan • Bug whisperer 🐞 Location Gdansk, Poland Pronouns she/her Joined Sep 28, 2025 • Aug 26 Dropdown menu Copy link Hide Haha never enough of Git 🙂 Like comment: Like comment: 2 likes Like Comment button Reply Collapse Expand Peter Vivo Peter Vivo Peter Vivo Follow The Vibe Archeologist. Creator of mordorjs. |> and touch bar fanatic from Hungary. God speed you! 1John1 + 5John17 |> 1Moses1 = (1Moses2 ... 4.22John21); alpha & omega = !![]; Location Pomaz Education streetwise Work full stack developer at TCS Joined Jul 24, 2020 • Aug 26 Dropdown menu Copy link Hide A best how to use git short document! Like comment: Like comment: 2 likes Like Comment button Reply Collapse Expand Sylwia Laskowska Sylwia Laskowska Sylwia Laskowska Follow Software dev • 10+ yrs of code & caffeine ☕ • Sci-fi fan • Bug whisperer 🐞 Location Gdansk, Poland Pronouns she/her Joined Sep 28, 2025 • Aug 26 Dropdown menu Copy link Hide Ooooh, thank you so much! ☺️ Now I can just send this article to juniors instead of explaining all of this on a call every time. 😂 Like comment: Like comment: 2 likes Like Comment button Reply Collapse Expand Peter Vivo Peter Vivo Peter Vivo Follow The Vibe Archeologist. Creator of mordorjs. |> and touch bar fanatic from Hungary. God speed you! 1John1 + 5John17 |> 1Moses1 = (1Moses2 ... 4.22John21); alpha & omega = !![]; Location Pomaz Education streetwise Work full stack developer at TCS Joined Jul 24, 2020 • Aug 26 Dropdown menu Copy link Hide Thats why is working so well Like comment: Like comment: 2 likes Like Thread Thread Sylwia Laskowska Sylwia Laskowska Sylwia Laskowska Follow Software dev • 10+ yrs of code & caffeine ☕ • Sci-fi fan • Bug whisperer 🐞 Location Gdansk, Poland Pronouns she/her Joined Sep 28, 2025 • Aug 26 Dropdown menu Copy link Hide Hahahaha, should've written this a few years ago! 😅 Like comment: Like comment: 1 like Like Comment button Reply Collapse Expand Ashley Childress Ashley Childress Ashley Childress Follow Distributed backend specialist. Perfectly happy playing second fiddle—it means I get to chase fun ideas, dodge meetings, and break things no one told me to touch, all without anyone questioning it. 😇 Location Georgia, United States Education University of West Georgia Pronouns She/Her Work SSE @ Home Depot, 8+ years Joined May 30, 2025 • Aug 26 Dropdown menu Copy link Hide This is exactly how I started writing! So I didn't have to explain myself multiple times. 😂 Great article! Like comment: Like comment: 2 likes Like Thread Thread Sylwia Laskowska Sylwia Laskowska Sylwia Laskowska Follow Software dev • 10+ yrs of code & caffeine ☕ • Sci-fi fan • Bug whisperer 🐞 Location Gdansk, Poland Pronouns she/her Joined Sep 28, 2025 • Aug 26 Dropdown menu Copy link Hide Thank you so much! 😄 Haha, I also wrote a few articles specifically for my juniors. But then somehow this whole writing thing took a rather unexpected turn. 😂 Like comment: Like comment: 3 likes Like Thread Thread Ashley Childress Ashley Childress Ashley Childress Follow Distributed backend specialist. Perfectly happy playing second fiddle—it means I get to chase fun ideas, dodge meetings, and break things no one told me to touch, all without anyone questioning it. 😇 Location Georgia, United States Education University of West Georgia Pronouns She/Her Work SSE @ Home Depot, 8+ years Joined May 30, 2025 • Aug 26 Dropdown menu Copy link Hide Sounds like we did much of the same thing!! It is a lot of fun. 🤩 Like comment: Like comment: 2 likes Like Comment button Reply Collapse Expand buildbasekit buildbasekit buildbasekit Follow Stop rebuilding auth and backend setup every time Clean Spring Boot boilerplates to ship faster Email hello@buildbasekit.com Joined Mar 13, 2026 • Aug 26 Dropdown menu Copy link Hide Hi Sylwia! 😂 git reflog is basically Git’s emergency contact. You hope you never need it, but the moment you accidentally nuke two days of work, suddenly it’s your best friend. Now I’m curious: which Git command has saved you from the biggest disaster so far? 😄 Like comment: Like comment: 3 likes Like Comment button Reply Collapse Expand Sylwia Laskowska Sylwia Laskowska Sylwia Laskowska Follow Software dev • 10+ yrs of code & caffeine ☕ • Sci-fi fan • Bug whisperer 🐞 Location Gdansk, Poland Pronouns she/her Joined Sep 28, 2025 • Aug 26 Dropdown menu Copy link Hide Haha, that’s a good question! 😄 I’d say git revert has definitely saved me from the biggest disasters. git reflog can save your work, sure, but git revert can save production. 😂 Like comment: Like comment: 3 likes Like Comment button Reply Collapse Expand nyaomaru nyaomaru nyaomaru Follow React / Vue / TypeScript / OSS Frontend engineer with 7+ years of experience. Building code simpler and more understandable architecture. Email nyaonyao0725@gmail.com Location Heerlen, the Netherlands Education Ritsumeikan University Joined Apr 19, 2024 • Aug 26 Dropdown menu Copy link Hide Git commands are basic, but really important for every developer. I think this will be a valuable article for many people! 😸 I use aliases in my .zshrc , for example, gc="git commit -S" . It makes my daily Git workflow a little bit faster. Do you have any similar tricks or customizations in your setup? I'm curious! 😸 Like comment: Like comment: 2 likes Like Comment button Reply Collapse Expand Sylwia Laskowska Sylwia Laskowska Sylwia Laskowska Follow Software dev • 10+ yrs of code & caffeine ☕ • Sci-fi fan • Bug whisperer 🐞 Location Gdansk, Poland Pronouns she/her Joined Sep 28, 2025 • Aug 26 Dropdown menu Copy link Hide Haha, you know what? I actually don’t! 😄 I know about Git aliases, but I prefer typing the commands manually so I don’t forget them, partly because then I can recite them from memory when explaining Git to juniors. 😂 But we do have a very funny Polish repo with Git aliases called “git kurwa” (“kurwa” is a Polish swear word 😅). So apparently we’ve found a very Polish solution to Git frustration. 😂 Like comment: Like comment: 2 likes Like Comment button Reply Collapse Expand nyaomaru nyaomaru nyaomaru Follow React / Vue / TypeScript / OSS Frontend engineer with 7+ years of experience. Building code simpler and more understandable architecture. Email nyaonyao0725@gmail.com Location Heerlen, the Netherlands Education Ritsumeikan University Joined Apr 19, 2024 • Aug 27 Dropdown menu Copy link Hide Actually, I don’t remember all the Git commands either. 😹 I only make aliases for the ones I use all the time. And I had no idea git kurwa existed! Thanks for introducing me! github.com/jakubnabrdalik/gitkurwa "Git, kurwa!" 😹 Like comment: Like comment: 1 like Like Comment button Reply Collapse Expand Gamya Gamya Gamya Follow Dream big, debug bigger 🐛✨ | Building things with Swift, one cute bug at a time | Anime lover 🍥 Email gamytsukiryu88@gmail.com Location United States Education masters in information assurance Pronouns she/her Work software developer (iOS) Joined Jan 3, 2026 • Aug 26 Dropdown menu Copy link Hide The merge vs rebase section is the one that finally made things click for me, I'd been using both without really understanding why I was choosing one over the other. The diagram of commits being replayed with new hashes is such a cleaner way to explain why rebasing shared history is risky. git stash is probably the one I reach for most often in my day to day, that moment where you're halfway through something and a bug report lands and you just need to put everything down cleanly without committing a mess. One I'd add at this level: git log --oneline --graph --all — not a command that does anything dramatic, but seeing the branch structure visually in the terminal helped me understand what merge and rebase were actually doing to my history way faster than any explanation did. Like comment: Like comment: 2 likes Like Comment button Reply Collapse Expand Sylwia Laskowska Sylwia Laskowska Sylwia Laskowska Follow Software dev • 10+ yrs of code & caffeine ☕ • Sci-fi fan • Bug whisperer 🐞 Location Gdansk, Poland Pronouns she/her Joined Sep 28, 2025 • Aug 26 Dropdown menu Copy link Hide Thanks so much for the comment! 😄 And yes, --graph is great! I have to admit that even though I type probably 90% of my Git commands manually, I still like using SourceTree, pretty much exclusively to look at the branch and commit tree. 😂 I’m definitely a visual learner, so being able to actually see the history makes everything much easier for me. Like comment: Like comment: 1 like Like Comment button Reply Collapse Expand Glen Allen Glen Allen Glen Allen Follow Building AI systems and making AI-generated apps stable, scalable, and production-ready. Location Morresville Pronouns He Joined Feb 7, 2024 • Aug 27 Dropdown menu Copy link Hide git reflog deserves more attention than it usually gets. Most Git commands are about changing the state of your repository, while reflog gives you a way to understand how you got there when something goes wrong. That makes it less of a daily workflow command and more of a recovery tool—and probably one of the best safety nets to learn before you actually need it. Like comment: Like comment: 2 likes Like Comment button Reply Collapse Expand Sylwia Laskowska Sylwia Laskowska Sylwia Laskowska Follow Software dev • 10+ yrs of code & caffeine ☕ • Sci-fi fan • Bug whisperer 🐞 Location Gdansk, Poland Pronouns she/her Joined Sep 28, 2025 • Aug 27 Dropdown menu Copy link Hide Exactly! Especially when you accidentally click the wrong thing somewhere, or when a rebase goes very, very wrong. 😂 That’s when git reflog suddenly becomes your best friend. Like comment: Like comment: 1 like Like Comment button Reply Collapse Expand Artjoms Stukans Artjoms Stukans Artjoms Stukans Follow Joined Aug 27, 2026 • Aug 27 Dropdown menu Copy link Hide Good framing, but worth to remember reflog lives inside .git, so it saves you only from yourself. When my SSD died the reflog died in same second, and what actually brought the thing back was a 13MB snapshot sitting on another machine. Local safety net and off machine copy are two different things, and most people have only first one. Like comment: Like comment: 1 like Like Comment button Reply Collapse Expand Sandro Garcia Sandro Garcia Sandro Garcia Follow Software Architect & Systems Researcher. Building decentralized AI agent networks & scalable architectures. Creator of IRC-A. Focused on distributed systems, FAISS, and semantic routing. Location Parnaíba, Brasil Education UNLP - UP Work Teach Lead at IAAutomations. Freelance Works Joined Jul 20, 2026 • Aug 26 Dropdown menu Copy link Hide You're making me feel old! When I was a junior, Git didn't even exist. I started back in the day with Visual SourceSafe 6.0, then moved to SVN (good old TortoiseSVN), until Microsoft eventually pushed everyone to TFS. I only really made the jump to Git around 2019 when I joined Bloomberg, and only switched my personal projects to it about two years ago after sticking with the MS ecosystem for ages. Great list of commands, by the way. My favorite: cherry-pick! Like comment: Like comment: 2 likes Like Comment button Reply Collapse Expand Sylwia Laskowska Sylwia Laskowska Sylwia Laskowska Follow Software dev • 10+ yrs of code & caffeine ☕ • Sci-fi fan • Bug whisperer 🐞 Location Gdansk, Poland Pronouns she/her Joined Sep 28, 2025 • Aug 26 Dropdown menu Copy link Hide Thank you so much, Sandro! And yes, that’s true, especially with older projects, SVN managed to stick around for years and years. I’ve actually worked with Git since the very beginning of my career, but here’s the plot twist: I used TortoiseGit. 😂 As far as I remember, it was basically the Git-enabled cousin of TortoiseSVN. So apparently our Git histories crossed paths after all! 😄 Like comment: Like comment: 2 likes Like Comment button Reply Collapse Expand Aliaksei Zelianouski Aliaksei Zelianouski Aliaksei Zelianouski Follow I build AI agents and let them run things - my blog, my projects, an AI Werewolf game played entirely by bots. Cybersecurity day job. Hands-on writeups, no hype. Joined Jun 10, 2026 • Aug 27 Dropdown menu Copy link Hide After 15 years of dealing with git, I learned push --force-with-lease , wow Like comment: Like comment: 2 likes Like Comment button Reply Collapse Expand Sylwia Laskowska Sylwia Laskowska Sylwia Laskowska Follow Software dev • 10+ yrs of code & caffeine ☕ • Sci-fi fan • Bug whisperer 🐞 Location Gdansk, Poland Pronouns she/her Joined Sep 28, 2025 • Aug 27 Dropdown menu Copy link Hide Haha, that’s exactly the beauty of these lists! 😄 You can be coding for 15 years, know 90% of the stuff on the list, and there’s still that one command that makes you go, “Wait, WHAT?!” 😂 Like comment: Like comment: 1 like Like Comment button Reply Collapse Expand jacob foster jacob foster jacob foster Follow SaaS founder building CRM and sales automation tools for startups and growing businesses. Joined May 28, 2026 • Aug 26 Dropdown menu Copy link Hide Great distinction between learning Git basics and learning the commands that actually make day-to-day development easier. The best Git lessons usually come from experienced developers sharing the small workflows and commands they rely on repeatedly. Looking forward to the rest of the list. Like comment: Like comment: 2 likes Like Comment button Reply Collapse Expand Sylwia Laskowska Sylwia Laskowska Sylwia Laskowska Follow Software dev • 10+ yrs of code & caffeine ☕ • Sci-fi fan • Bug whisperer 🐞 Location Gdansk, Poland Pronouns she/her Joined Sep 28, 2025 • Aug 26 Dropdown menu Copy link Hide Thank you so much! And yes, exactly! In the beginning, you can absolutely survive without these commands, but they quickly become pretty essential if you don’t want to lose your mind working with Git every day. 😂 Like comment: Like comment: 1 like Like Comment button Reply Collapse Expand Niuniu Ox Niuniu Ox Niuniu Ox Follow Joined Aug 23, 2026 • Aug 26 Dropdown menu Copy link Hide The git rebase -i + git reflog combo saved me last week after I force-pushed over a teammate's commit — reflog found the lost SHA in about 10 seconds. One command I'd add to this list: git log -S<string> (pickaxe search) — it finds the commit that introduced or removed a specific string, which is how I tracked down who silently dropped an env var check three months ago. Grepping history by diff content beats reading 500 commit subjects. Do you find interactive rebase actually safe to teach juniors, or do you steer them toward git merge --no-ff until they've internalized reflog recovery first? Like comment: Like comment: 2 likes Like Comment button Reply Collapse Expand Sylwia Laskowska Sylwia Laskowska Sylwia Laskowska Follow Software dev • 10+ yrs of code & caffeine ☕ • Sci-fi fan • Bug whisperer 🐞 Location Gdansk, Poland Pronouns she/her Joined Sep 28, 2025 • Aug 26 Dropdown menu Copy link Hide Oh, that git log -S tip is great! 😄 I’d probably have reached for git blame and started digging from there, so I’m definitely keeping this one in mind! As for interactive rebase, juniors usually come in already knowing how to work with merges, so I tend to introduce rebase fairly early. Of course, how quickly they actually start using it confidently varies. 😅 git commit --amend, on the other hand, they pick up almost immediately. 😂 Although I guess I should be speaking in the past tense here, I haven’t had many juniors around lately. :( Like comment: Like comment: 1 like Like Comment button Reply View full discussion (47 comments) Code of Conduct • Report abuse Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink . Hide child comments as well Confirm For further actions, you may consider blocking this person and/or reporting abuse Sylwia Laskowska Follow Software dev • 10+ yrs of code & caffeine ☕ • Sci-fi fan • Bug whisperer 🐞 Location Gdansk, Poland Pronouns she/her Joined Sep 28, 2025 More from Sylwia Laskowska 7 Productivity Tips That Sound Wrong (But Actually Work) # productivity # mentalhealth # career Who Here Has Worked with Legacy? The Longer You Wait, the Worse It Gets # javascript # webdev # programming # architecture Every Developer Is Lying About Something — And AI Won’t Fix It # discuss # productivity DEV Community — A space to discuss and keep up software development and manage your software career Home DEV Challenges DEV++ Videos DEV Education Tracks DEV Help Advertise on DEV Organization Accounts DEV Showcase About Contact Free Postgres Database DEV Shop MLH Code of Conduct Privacy Policy Terms of Use Built on Forem — the open source software that powers DEV and other inclusive communities. Made with love and Ruby on Rails . DEV Community © 2016 - 2026. We're a place where coders share, stay up-to-date and grow their careers. Log in Create account var userSignedIn = false; if (document.readyState === 'complete' || document.readyState === 'interactive') { initAuth(); } else { document.addEventListener('DOMContentLoaded', initAuth); } function initAuth() { var paramToken = new URLSearchParams(window.location.search).get('jwt'); if (paramToken && !userSignedIn) { authenticateUser(paramToken); } else { var iframe = document.createElement('iframe'); iframe.style.display = 'none'; iframe.src = 'https://forem.com/auth_pass/iframe?passed_domain=' + encodeURIComponent(window.location.origin || (window.location.protocol + '//' + window.location.host)); document.body.appendChild(iframe); window.addEventListener('message', function(event) { if (event.origin !== 'https://forem.com' && event.origin !== window.location.origin) { return; } var data = event.data; if (data.authenticated && !userSignedIn) { authenticateUser(data.token); } else if(data.authenticated && window.ReactNativeWebView && window.ReactNativeWebView.postMessage) { window.ReactNativeWebView.postMessage(JSON.stringify({ action: 'login', token: data.token, })); } }); } function authenticateUser(token) { fetch('/auth_pass/token_login', { method: 'POST', credentials: 'include', headers: { 'Content-Type': 'application/json', 'X-CSRF-Token': getMetaContent('csrf-token'), }, body: JSON.stringify({ token: token }), }) .then(function(response) { return response.json(); }) .then(function(data) { if (data.success) { if (document.head.querySelector('meta[name="user-signed-in"][content="false"]')) { // Reload the page to update the user's state location.reload(); } } }) .catch(function(error) { console.error('Error during authentication:', error); }); } function getMetaContent(name) { var element = document.querySelector('meta[name="' + name + '"]'); return element ? element.getAttribute('content') : ''; } }
📖 Read full article on Dev.to Trending →