{"componentChunkName":"component---src-templates-post-tsx","path":"/git-reset-not-enough/","result":{"data":{"logo":{"childImageSharp":{"fixed":{"base64":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAACXBIWXMAAGwGAABsBgFnvUbqAAAC5UlEQVQ4y5WUT0gUcRTHvzuzS+scNg9Z2Epjiwdhy13/0BzWDTx1jYKIQCMU2VYQPC9SeNgg7KIdklhYPHRQhBA8SOAKHcJsRRfRU9BNTFHapXB3/jx548wyrqPVgzfvNzO/9/l9f+/3B/iL+Xw+Dh77fWNjw/lbWFhYwD9bXV0d9vf37dcHAD56vd7PAD4AiNlQn8/ncQ7qaqIoOpWlFUWh2dlZyufzNDMzQy0tLQTgmTOHiE4aHo+Z5xEEQXRARCvea29vJ03TdCKq7OzsaLlcrry1tUWNjY1HABQAVwFcqwJd5IqyLAtWO5vJZIhh/BgbGzNYzN7enj46OkqyLBdTqdRPRVF+AAiaNbASeaQ3AGSrfmJzczM3Py0tLTFLIyLj4OCAVldXDf4wMTGhDw4OsnJKJpOs9rqtKCBJ0vf+/n5qaGj4BeChQ+3bqakpzlHL5TI5zOD+6XSaFhcXSZKkdz09PdWkF4lEgjv9WV9fp6amJi7GfQASgGQoFKLd3V1WYlQq5syNzc1NCgQCh9Fo9Gt9ff1rAJeqW83v9xfW1tbsaWnLy8usVGtrazuMx+OlYDCoTU5OmiBLpTY/P8+DfmFAKBQ6tRY3w+FwWdfNUhiaxkzSi8UilUolYgC7qqpm3QzjJPCjs7NTA3CrZlcgGo/HzU66rhtsNpzBVrRhZlRV1Qx9fX2s8nEtMBKLxU4BOc/NbYWWWm1kZISBiVrgjdbW1t9WbapAN7O/2wp7e3sZ+KgWKHi93m8rKytmsSuVSpXoppBnwc7tSCTCNQzbHOfJSFnb5oihnMAqeGo1zkeQYUdzc3OsLsfJXV1dZy6Gy4IgbA8NDVGhUCBrMXi51Ro3T0sul7Mvh7tu6mz6FQAv/X7/dnd3Nw0PD/PRounpacpmszQ+Pk4DAwPU0dGhA8gDeHLOPXDmI+/4OwCeW2c7A+A9gFcAngK4fU7emfvP41ypi8y6pkT8hwlWgpsLF2UeA2cncRiRWBqkAAAAAElFTkSuQmCC","width":400,"height":400,"src":"/static/c145ae02d8428dda1fa96de2fe8a40ed/497c6/rubber-duck-logo.png","srcSet":"/static/c145ae02d8428dda1fa96de2fe8a40ed/497c6/rubber-duck-logo.png 1x,\n/static/c145ae02d8428dda1fa96de2fe8a40ed/2a4de/rubber-duck-logo.png 1.5x,\n/static/c145ae02d8428dda1fa96de2fe8a40ed/ee604/rubber-duck-logo.png 2x"}}},"markdownRemark":{"html":"<h2>Introduction</h2>\n<p>I ran into a small but frustrating issue recently. Git was telling me my branch was ahead of origin by a couple of commits, even though I just wanted to throw everything away and go back to the remote version.</p>\n<p>My first instinct was the usual:</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">git</span> reset <span class=\"token parameter variable\">--hard</span></code></pre></div>\n<p>But nothing changed. The “2 unpushed commits” were still there.</p>\n<h3>What’s actually happening</h3>\n<p><code class=\"language-text\">git reset --hard</code> on its own only resets your working directory to your current <code class=\"language-text\">HEAD</code>. If your local branch already includes those extra commits, Git considers that the correct state. So it doesn’t remove anything.</p>\n<p>In other words, you’re resetting to the wrong place.</p>\n<h3>The fix</h3>\n<p>What worked straight away was resetting to the remote branch instead:</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">git</span> fetch origin\n<span class=\"token function\">git</span> reset <span class=\"token parameter variable\">--hard</span> origin/branch-name</code></pre></div>\n<h3>Why this works</h3>\n<ul>\n<li><code class=\"language-text\">git fetch origin</code> updates your view of the remote</li>\n<li><code class=\"language-text\">git reset --hard origin/branch-name</code> moves your local branch pointer back to exactly where the remote branch is</li>\n</ul>\n<p>This effectively discards any local commits that haven’t been pushed.</p>\n<h3>A quick note</h3>\n<p>This is a destructive operation. Any unpushed commits will be lost, so it’s worth double-checking that you really don’t need them.</p>\n<h3>Takeaway</h3>\n<p>If you’re trying to get your branch back in sync with the remote and <code class=\"language-text\">git reset --hard</code> doesn’t help, it’s probably because you’re resetting to your own <code class=\"language-text\">HEAD</code>. Point it at <code class=\"language-text\">origin/branch-name</code> instead, and the issue goes away.</p>","htmlAst":{"type":"root","children":[{"type":"element","tagName":"h2","properties":{},"children":[{"type":"text","value":"Introduction"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"I ran into a small but frustrating issue recently. Git was telling me my branch was ahead of origin by a couple of commits, even though I just wanted to throw everything away and go back to the remote version."}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"My first instinct was the usual:"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"bash"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-bash"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-bash"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"git"}]},{"type":"text","value":" reset "},{"type":"element","tagName":"span","properties":{"className":["token","parameter","variable"]},"children":[{"type":"text","value":"--hard"}]}]}]}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"But nothing changed. The “2 unpushed commits” were still there."}]},{"type":"text","value":"\n"},{"type":"element","tagName":"h3","properties":{},"children":[{"type":"text","value":"What’s actually happening"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"git reset --hard"}]},{"type":"text","value":" on its own only resets your working directory to your current "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"HEAD"}]},{"type":"text","value":". If your local branch already includes those extra commits, Git considers that the correct state. So it doesn’t remove anything."}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"In other words, you’re resetting to the wrong place."}]},{"type":"text","value":"\n"},{"type":"element","tagName":"h3","properties":{},"children":[{"type":"text","value":"The fix"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"What worked straight away was resetting to the remote branch instead:"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"div","properties":{"className":["gatsby-highlight"],"dataLanguage":"bash"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-bash"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-bash"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"git"}]},{"type":"text","value":" fetch origin\n"},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"git"}]},{"type":"text","value":" reset "},{"type":"element","tagName":"span","properties":{"className":["token","parameter","variable"]},"children":[{"type":"text","value":"--hard"}]},{"type":"text","value":" origin/branch-name"}]}]}]},{"type":"text","value":"\n"},{"type":"element","tagName":"h3","properties":{},"children":[{"type":"text","value":"Why this works"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"git fetch origin"}]},{"type":"text","value":" updates your view of the remote"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"git reset --hard origin/branch-name"}]},{"type":"text","value":" moves your local branch pointer back to exactly where the remote branch is"}]},{"type":"text","value":"\n"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"This effectively discards any local commits that haven’t been pushed."}]},{"type":"text","value":"\n"},{"type":"element","tagName":"h3","properties":{},"children":[{"type":"text","value":"A quick note"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"This is a destructive operation. Any unpushed commits will be lost, so it’s worth double-checking that you really don’t need them."}]},{"type":"text","value":"\n"},{"type":"element","tagName":"h3","properties":{},"children":[{"type":"text","value":"Takeaway"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"If you’re trying to get your branch back in sync with the remote and "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"git reset --hard"}]},{"type":"text","value":" doesn’t help, it’s probably because you’re resetting to your own "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"HEAD"}]},{"type":"text","value":". Point it at "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"origin/branch-name"}]},{"type":"text","value":" instead, and the issue goes away."}]}],"data":{"quirksMode":false}},"excerpt":"Introduction I ran into a small but frustrating issue recently. Git was telling me my branch was ahead of origin by a couple of commits…","timeToRead":1,"frontmatter":{"title":"When git reset --hard Isn’t Enough","userDate":"5 June 2026","date":"2026-06-05T00:00:00.000Z","tags":["Git","All"],"image":{"childImageSharp":{"fluid":{"base64":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAFCAYAAABFA8wzAAAACXBIWXMAAB7CAAAewgFu0HU+AAABR0lEQVQY01WQS0sCYRSG5y+17w/0CwqDFm2jKIiiRUgtuhEhmJC7LouIIKILuSiCsshuCDneqCzUCnUmR78Z5xt1njDC6izPed8HzqMANLIZxMoCrmXyd16e4pyf7JJKRpFaAScVw6w3MNIJKtlXLOmQv75AlD/RCgXSdzcozv0Vxmg/IjBLZckLUnIc2sI/P8L2ho+gbwLvmIdKNoMRCSOaLsVIGD2pIqRD/GCHqlbiI58jEjpEaYG0rg7MtQD6UC+kVALLk0yNdnO0u8r0uAffzCBVs4JRsykLk/fwKXr8AcOq4fx849TryHoDxW02MYOLlAd6sI73v4/+uWEG+joJ7a2TeVSJ3p6hFT/aKiwh0HUdIQSJnU2MUpFCsYS0bZRWoOXOid23C2+5Z2LRS6Ss/XPqus1fqGVhCkEpqVI1yti2/b3/Aib0YLDxunSOAAAAAElFTkSuQmCC","aspectRatio":3.858921161825726,"src":"/static/7a97243ee77e0f2af80f705cae4fd15e/6ab48/git_banner.png","srcSet":"/static/7a97243ee77e0f2af80f705cae4fd15e/c5c6c/git_banner.png 930w,\n/static/7a97243ee77e0f2af80f705cae4fd15e/6ab48/git_banner.png 1714w","sizes":"(max-width: 1714px) 100vw, 1714px"}}},"author":{"id":"Dushyant","bio":"Check about page for details.","avatar":{"children":[{"__typename":"ImageSharp","fixed":{"base64":"data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAATABQDASIAAhEBAxEB/8QAGAABAQEBAQAAAAAAAAAAAAAAAAQCBQH/xAAXAQEBAQEAAAAAAAAAAAAAAAABAwIE/9oADAMBAAIQAxAAAAGC3Hg4dQPBrOiN41P/xAAbEAACAwEBAQAAAAAAAAAAAAABAgADESEEMv/aAAgBAQABBQIKRNBq0TQi+b7LV7vahFHP/8QAGBEAAgMAAAAAAAAAAAAAAAAAABEBAhD/2gAIAQMBAT8BcIZbP//EABcRAAMBAAAAAAAAAAAAAAAAAAEQEQL/2gAIAQIBAT8Bhqyv/8QAHBAAAgICAwAAAAAAAAAAAAAAAREAMQIQICIy/9oACAEBAAY/AqiONaIbc7VPA4f/xAAdEAEAAwABBQAAAAAAAAAAAAABABEhQRAxYYGx/9oACAEBAAE/ISLx5jZEdCHbpcbDiA1R+4TQeoJQwLgOif/aAAwDAQACAAMAAAAQJC8+/8QAGBEBAQEBAQAAAAAAAAAAAAAAAQAhMXH/2gAIAQMBAT8QC8WtG5i//8QAGREAAgMBAAAAAAAAAAAAAAAAADEBESGR/9oACAECAQE/EOwWUOSz/8QAHxABAQACAQQDAAAAAAAAAAAAAREAIVExQWGBcaHB/9oACAEBAAE/ECCZsaWvrF6FZ3RLvhvTLdbfkf3Eo1h5d9n16yVHiJb7nfJTRa5HOsQildYEIbMrqbmf/9k=","width":400,"height":388,"src":"/static/ca50b870313d79772bec7be9f9d9786f/64b17/dp-profile.jpg","srcSet":"/static/ca50b870313d79772bec7be9f9d9786f/64b17/dp-profile.jpg 1x,\n/static/ca50b870313d79772bec7be9f9d9786f/39f27/dp-profile.jpg 1.5x,\n/static/ca50b870313d79772bec7be9f9d9786f/a1eb1/dp-profile.jpg 2x"}}]}}}},"relatedPosts":{"totalCount":2,"edges":[{"node":{"id":"3db4f12b-e942-557b-ab7b-9ecfafb92c6b","timeToRead":1,"excerpt":"Introduction I ran into a small but frustrating issue recently. Git was telling me my branch was ahead of origin by a couple of commits…","frontmatter":{"title":"When git reset --hard Isn’t Enough"},"fields":{"slug":"/git-reset-not-enough/"}}},{"node":{"id":"098c7419-48de-59f6-972b-5be6ea340952","timeToRead":2,"excerpt":"Special thanks to my fantastic colleague Fatih Kucukkara for helping figure these details out. 🧩 What They Are and How to Fix Them If you…","frontmatter":{"title":"Git Branch Naming Conflicts in Azure DevOps"},"fields":{"slug":"/git-ado-branch-case-sensitivity/"}}}]}},"pageContext":{"slug":"/git-reset-not-enough/","prev":{"excerpt":"When working with Pulumi, especially coming from traditional .NET development, you might expect that wrapping resource creation in a try…","timeToRead":5,"frontmatter":{"title":"Why Try-Catch Doesn't Work with Pulumi","tags":["Pulumi","All"],"date":"2025-10-10T16:30:00.000Z","draft":false,"image":{"childImageSharp":{"fluid":{"aspectRatio":1.9096509240246407,"base64":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAKCAYAAAC0VX7mAAAACXBIWXMAAAsTAAALEwEAmpwYAAAA4klEQVQoz62SwQuCMBTG/b8910m8R+JZgo5d9aZ4EfEmhBShNAtE7bLl/KKRNlIJo8HjfXsb3368NwV/Xkon2rbtcxdyfZbhp5msOeejeurhAaHQrJ4kGCOWa8qbhotCcw3B0xUo8cEY4LousiwDYwxJkog7VVWhLEsQQkApHRL22KzB3fNwsXcItwHOJ4LFcgFjbcA0TaiqCsuyoOu62GuaJsynDZ85OeC48bF3U9yqGkVRIM9zOI6DKIpg2zbiOBbUQRAI8q89bCibNdnRHr5ORr9PN2E55KlPEraS6a//8AHmEQdX83PRqwAAAABJRU5ErkJggg==","sizes":"(max-width: 1200px) 100vw, 1200px","src":"/static/f72145e8231fc83774e5776f66ed67a7/f3583/pulumi-banner.png","srcSet":"/static/f72145e8231fc83774e5776f66ed67a7/c5c6c/pulumi-banner.png 930w,\n/static/f72145e8231fc83774e5776f66ed67a7/f3583/pulumi-banner.png 1200w"}}},"author":{"id":"Dushyant","bio":"Check about page for details.","avatar":{"children":[{"fixed":{"src":"/static/ca50b870313d79772bec7be9f9d9786f/64b17/dp-profile.jpg"}}]}}},"fields":{"layout":"post","slug":"/pulumi-try-catch/"}},"next":null,"primaryTag":"Git"}},"staticQueryHashes":["3100086437","794779027","990608418"]}