<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: AYUSH PORWAL</title>
    <description>The latest articles on DEV Community by AYUSH PORWAL (@the_code_witcher).</description>
    <link>https://dev.to/the_code_witcher</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1897933%2F77f10d17-7cd6-4caf-8145-b35acb117c35.png</url>
      <title>DEV Community: AYUSH PORWAL</title>
      <link>https://dev.to/the_code_witcher</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/the_code_witcher"/>
    <language>en</language>
    <item>
      <title>My quick git fix for a recent merge conflict</title>
      <dc:creator>AYUSH PORWAL</dc:creator>
      <pubDate>Mon, 24 Mar 2025 10:09:28 +0000</pubDate>
      <link>https://dev.to/the_code_witcher/my-quick-git-fix-for-a-recent-merge-conflict-36ah</link>
      <guid>https://dev.to/the_code_witcher/my-quick-git-fix-for-a-recent-merge-conflict-36ah</guid>
      <description>&lt;p&gt;Today morning, as any other work day, I logged in to my GitHub account to check the status of my open pull requests. I saw I had some merge conflicts and I needed to sync with the main.&lt;/p&gt;

&lt;p&gt;I found myself in a situation where I needed to delete the last two commits and re-sync with the main.&lt;/p&gt;

&lt;p&gt;First of all, I switched to main and pulled the latest changes&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git pull origin main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then I checked back to my working branch. First of all, I need to delete the last two commits. We have two options:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;: &lt;span class="s1"&gt;'
this will take you to the commit before the last two commits and then keep the changes of the last two commits in your work directory
'&lt;/span&gt;
git reset &lt;span class="nt"&gt;--soft&lt;/span&gt; HEAD~2

// or

: &lt;span class="s1"&gt;'
this will take you to the commit before the last two commits but you will lose your last two commits
'&lt;/span&gt;
git reset &lt;span class="nt"&gt;--hard&lt;/span&gt; HEAD~2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In my case I did't require the last two commits changes so I went with the option 2.&lt;/p&gt;

&lt;p&gt;The I synced my current branch with the main&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git merge main

: &lt;span class="s1"&gt;'
we can also use the re-basing technique but I was more comfortable with the merge in this situation
'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, we need to push these changes to the remote. Since we are changing the git history, we would require to use &lt;code&gt;--force&lt;/code&gt; flag. We have two options again:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;
git push origin &amp;lt;current_branch&amp;gt; &lt;span class="nt"&gt;--force&lt;/span&gt;

// and

git push origin &amp;lt;curren_branch&amp;gt; &lt;span class="nt"&gt;--force-with-lease&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;--force&lt;/code&gt; will overwrite the remote history unconditionally.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;--force-with-lease&lt;/code&gt; will only overwrite the remote history if the remote branch is unchanged since our last fetch preventing any accidental overwrite of other people's work.&lt;/p&gt;

&lt;p&gt;If you ever find yourself in this situation. I hope this helps.&lt;/p&gt;

</description>
      <category>github</category>
      <category>git</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
