<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Git &#8212; onthecode</title>
	<atom:link href="https://onthecode.co.uk/blog/category/git/feed" rel="self" type="application/rss+xml" />
	<link>https://onthecode.co.uk/blog/category/git</link>
	<description>onthecode blog</description>
	<lastBuildDate>Fri, 30 Dec 2022 00:36:11 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.3</generator>

<image>
	<url>https://onthecode.co.uk/wp-content/uploads/2019/02/onthecode-icon-1-100x100.png</url>
	<title>Git &#8212; onthecode</title>
	<link>https://onthecode.co.uk/blog/category/git</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How to Switch Git Branch with Local Changes</title>
		<link>https://onthecode.co.uk/blog/how-to-switch-git-branch-with-local-changes</link>
					<comments>https://onthecode.co.uk/blog/how-to-switch-git-branch-with-local-changes#respond</comments>
		
		<dc:creator><![CDATA[Umut Esen]]></dc:creator>
		<pubDate>Tue, 14 Jun 2022 09:49:31 +0000</pubDate>
				<category><![CDATA[Git]]></category>
		<guid isPermaLink="false">https://onthecode.co.uk/?p=4617</guid>

					<description><![CDATA[<p>I find myself working on the wrong branch locally far too many times &#8211; enough to write a post about it. If you have been working on the wrong branch, your commit could be blocked by git: Git stash is extremely useful when you want to temporarily save undone or messy work, while you want to do something on another branch. You can use: git stash&#160;to save your work git checkout mybranch git stash pop&#160;to load your last work Here a some stash commands I find useful: git stash list view everything you have stashed git stash show inspect a stash git stash apply restore a stash on top of your current branch If you have somehow already committed to the wrong branch, you will have to: git checkout -b mybranch to create a new branch git checkout master to checkout back to master branch git reset --hard origin/master to reset master with remote and remove local commits Hopefully this quick post helped move your local changes to the correct branch. Do you know another way to switch git branch with local changes? Let me know in the comments below!</p>
<p>The post <a href="https://onthecode.co.uk/blog/how-to-switch-git-branch-with-local-changes">How to Switch Git Branch with Local Changes</a> appeared first on <a href="https://onthecode.co.uk">onthecode</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>I find myself working on the wrong branch locally far too many times &#8211; enough to write a post about it. </p>



<p>If you have been working on the wrong branch, your commit could be blocked by git:</p>


<pre class="wp-block-code"><span><code class="hljs language-bash">Please, commit your changes or stash them before you can switch branches.</code></span></pre>


<p>Git stash is extremely useful when you want to temporarily save undone or messy work, while you want to do something on another branch.</p>



<p>You can use:</p>



<ol class="wp-block-list"><li><code>git stash</code>&nbsp;<em>to save your work</em></li><li><code>git checkout mybranch</code></li><li><code>git stash pop</code>&nbsp;<em>to load your last work</em></li></ol>



<p>Here a some stash commands I find useful:</p>



<ul class="wp-block-list"><li><code>git stash list</code> <em>view everything you have stashed</em></li><li><code>git stash show</code> <em>inspect a stash</em></li><li><code>git stash apply</code> <em>restore a stash on top of your current branch</em></li></ul>



<p>If you have somehow already committed to the wrong branch, you will have to:</p>



<ol class="wp-block-list"><li><code>git checkout -b mybranch</code> <em>to create a new branch</em></li><li><code>git checkout master</code> <em>to checkout back to master branch</em></li><li><code>git reset --hard origin/master</code> <em>to reset master with remote and remove local commit</em>s</li></ol>



<p>Hopefully this quick post helped move your local changes to the correct branch. </p>



<p>Do you know another way to switch git branch with local changes? Let me know in the comments below!  </p>
<p>The post <a href="https://onthecode.co.uk/blog/how-to-switch-git-branch-with-local-changes">How to Switch Git Branch with Local Changes</a> appeared first on <a href="https://onthecode.co.uk">onthecode</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://onthecode.co.uk/blog/how-to-switch-git-branch-with-local-changes/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
