<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://charlesreid1.com/w/index.php?action=history&amp;feed=atom&amp;title=Git%2FDelete_Commits_from_Master</id>
	<title>Git/Delete Commits from Master - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://charlesreid1.com/w/index.php?action=history&amp;feed=atom&amp;title=Git%2FDelete_Commits_from_Master"/>
	<link rel="alternate" type="text/html" href="https://charlesreid1.com/w/index.php?title=Git/Delete_Commits_from_Master&amp;action=history"/>
	<updated>2026-06-19T17:07:11Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.12</generator>
	<entry>
		<id>https://charlesreid1.com/w/index.php?title=Git/Delete_Commits_from_Master&amp;diff=22251&amp;oldid=prev</id>
		<title>Admin at 23:50, 17 November 2017</title>
		<link rel="alternate" type="text/html" href="https://charlesreid1.com/w/index.php?title=Git/Delete_Commits_from_Master&amp;diff=22251&amp;oldid=prev"/>
		<updated>2017-11-17T23:50:38Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 23:50, 17 November 2017&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l66&quot;&gt;Line 66:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 66:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;hint: See the &amp;#039;Note about fast-forwards&amp;#039; in &amp;#039;git push --help&amp;#039; for details.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;hint: See the &amp;#039;Note about fast-forwards&amp;#039; in &amp;#039;git push --help&amp;#039; for details.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/pr&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/pr&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Category:Git]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Category:Github]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://charlesreid1.com/w/index.php?title=Git/Delete_Commits_from_Master&amp;diff=22249&amp;oldid=prev</id>
		<title>Admin: Created page with &quot;Scenario:  * You have a fork of a remote repositoroy * You&#039;ve prepared a commit, but you accidentally pushed the commit to the master branch instead of creating a branch for a...&quot;</title>
		<link rel="alternate" type="text/html" href="https://charlesreid1.com/w/index.php?title=Git/Delete_Commits_from_Master&amp;diff=22249&amp;oldid=prev"/>
		<updated>2017-11-17T23:48:40Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;Scenario:  * You have a fork of a remote repositoroy * You&amp;#039;ve prepared a commit, but you accidentally pushed the commit to the master branch instead of creating a branch for a...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Scenario: &lt;br /&gt;
* You have a fork of a remote repositoroy&lt;br /&gt;
* You&amp;#039;ve prepared a commit, but you accidentally pushed the commit to the master branch instead of creating a branch for all your fixes&lt;br /&gt;
* You need to keep the master branch clean&lt;br /&gt;
&lt;br /&gt;
Here&amp;#039;s what this solution does:&lt;br /&gt;
* ASSUMPTION: You have your commit/changes backed up somewhere&lt;br /&gt;
* Replace the master branch of your fork (the remote branch that you own) with the master branch of the upstream (the master branch of the remote repo that you forked)&lt;br /&gt;
&lt;br /&gt;
This shares some similarities with [[Git/Delete Remote Branch]].&lt;br /&gt;
&lt;br /&gt;
===The procedure===&lt;br /&gt;
&lt;br /&gt;
Here&amp;#039;s what the procedure will look like:&lt;br /&gt;
&lt;br /&gt;
Check out a non-master branch (this might be the new branch that you are going to do your work on, or it might be a dummy branch you&amp;#039;ll delete when this is all over):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ git checkout -b not-the-master&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Delete the master branch (MAKE SURE YOU BACK UP YOUR COMMITS TO MASTER!!!):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ git branch -d master&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At this point, if you try to push this (deleted) master to the remote, it will fail:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ git push origin --delete master&lt;br /&gt;
To https://github.com/ours/repo.git&lt;br /&gt;
 ! [remote rejected] master (refusing to delete the current branch: refs/heads/master)&lt;br /&gt;
error: failed to push some refs to &amp;#039;https://github.com/ours/repo.git&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So instead, what we&amp;#039;ll do is we&amp;#039;ll make a new master branch directly from the upstream master (again, that&amp;#039;s the master branch of the original repo that we forked):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ git checkout -b master remotes/open/master&lt;br /&gt;
Branch master set up to track remote branch master from open.&lt;br /&gt;
Switched to a new branch &amp;#039;master&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we have a fresh copy of master that looks just like the master branch of the upstream repo that we forked. You&amp;#039;re almost there!&lt;br /&gt;
&lt;br /&gt;
The last step is to push this new master to the master branch of your repository. You&amp;#039;ll have to piss off all the git purists by using the --force flag, and pushing the local master branch to the remote master branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ git push --force origin master:master&lt;br /&gt;
Total 0 (delta 0), reused 0 (delta 0)&lt;br /&gt;
To https://github.com/ours/repo.git&lt;br /&gt;
 + e526633...dc3cfea master -&amp;gt; master (forced update)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As a side note, the force flag says &amp;quot;Ignore any errors due to the current master branch in the remote repository being ahead of the local master branch that we&amp;#039;re trying to push.&amp;quot; If you don&amp;#039;t include the force flag, here&amp;#039;s what will happen:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ git push origin master:master&lt;br /&gt;
To https://github.com/ours/repo.git&lt;br /&gt;
 ! [rejected]        master -&amp;gt; master (non-fast-forward)&lt;br /&gt;
error: failed to push some refs to &amp;#039;https://github.com/ours/repo.git&amp;#039;&lt;br /&gt;
hint: Updates were rejected because the tip of your current branch is behind&lt;br /&gt;
hint: its remote counterpart. Integrate the remote changes (e.g.&lt;br /&gt;
hint: &amp;#039;git pull ...&amp;#039;) before pushing again.&lt;br /&gt;
hint: See the &amp;#039;Note about fast-forwards&amp;#039; in &amp;#039;git push --help&amp;#039; for details.&lt;br /&gt;
&amp;lt;/pr&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
</feed>