
<?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>Ankit Ahuja &#187; git</title>
	<atom:link href="http://ankitahuja.com/blog/tag/git/feed/" rel="self" type="application/rss+xml" />
	<link>http://ankitahuja.com</link>
	<description>Personal Website and Blog of Ankit Ahuja</description>
	<lastBuildDate>Sun, 04 Dec 2011 01:39:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>git Cheatsheet</title>
		<link>http://ankitahuja.com/blog/development/git-cheatsheet/</link>
		<comments>http://ankitahuja.com/blog/development/git-cheatsheet/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 11:00:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[git]]></category>
		<guid isPermaLink="false">http://ankitahuja.com/?p=462</guid>
		<description><![CDATA[When you&#8217;re new to git, it can get difficult to wrap your head around it at first. This is especially true if you&#8217;re migrating from subversion or when you&#8217;d rather spend more time writing your code than trying to learn git. Git requires some learning, and you might as well spend the time doing it [...]]]></description>
			<content:encoded><![CDATA[<p>When you&#8217;re new to git, it can get difficult to wrap your head around it at first. This is especially true if you&#8217;re migrating from subversion or when you&#8217;d rather spend more time writing your code than trying to learn git.</p>
<p>Git requires some learning, and you might as well spend the time doing it rather than wondering what just happened after running a command. <a href="http://learn.github.com">Learn.github</a> is a good place to start to learn the basics.</p>
<p>But even after spending some time learning git, there are going to be times that you&#8217;ve to painfully search the web/manual for basic stuff like working with remote branches or more complex stuff like handling a failed merge.</p>
<p>For the same reason, I&#8217;m creating this post as a reference point for myself to avoid repetitive searches. I&#8217;ll keep adding new commands here if and when I use them.</p>
<p>This is no way near to a complete reference for git and there might be better ways to do the things listed here. These are just the commands I use the most, in the manner I prefer to use them.</p>
<h2>Basics</h2>
<ul>
<li>
		Commit and Stage all changes
<pre class="brush: bash; light: true; title: ;">git commit -am &quot;log message&quot;</pre>
</li>
<li>
		Push Changes to remote repo
<pre class="brush: bash; light: true; title: ;">git push</pre>
</li>
<li>
		Pull Changes to local repo
<pre class="brush: bash; light: true; title: ;">git pull</pre>
</li>
<li>
		Check current status of working tree
<pre class="brush: bash; light: true; title: ;">git status</pre>
</li>
<li>
		View diff
<pre class="brush: bash; light: true; title: ;">git diff</pre>
</li>
<li>
		Discard local uncommitted changes to a file (in this case, abc.txt)
<pre class="brush: bash; light: true; title: ;">git checkout -- abc.txt</pre>
</li>
</ul>
<h2>Branches <span style="font-size: 14px; font-weight: normal; font-style: italic;"> ( Branch name is assumed to be &#8216;abc&#8217; )</span></h2>
<p><strong>Working with local branches</strong></p>
<ul>
<li>
		Create a branch
<pre class="brush: bash; light: true; title: ;">git branch abc</pre>
</li>
<li>
	Switch to a branch
<pre class="brush: bash; light: true; title: ;">git checkout abc</pre>
</li>
<li>
	View all existing branches
<pre class="brush: bash; light: true; title: ;">git branch</pre>
</li>
<li>
Remove a branch
<pre class="brush: bash; light: true; title: ;">git branch -d abc</pre>
</li>
<li>
Merge a branch</p>
<pre class="brush: bash; title: ;">
# In this case, merging abc into master
git checkout master
git merge abc
</pre>
</li>
</ul>
<p><strong> Working with remote branches </strong></p>
<ul>
<li>
Push a local branch to remote repo
<pre class="brush: bash; light: true; title: ;">git push origin abc</pre>
</li>
<li>
Delete a remote branch
<pre class="brush: bash; light: true; title: ;">git push origin :abc</pre>
</li>
<li>
Setup a local branch to track a remote branch
<pre class="brush: bash; light: true; title: ;">git branch --track abc origin/abc</pre>
</li>
<li>
Create a local branch, push it to remote repo. and then pull changes from it</p>
<pre class="brush: bash; title: ;">
# Creating the new branch and switching to it
git checkout -b abc;
# Pushing the changes
git push
# Meanwhile someone else made changes to the remote version
# Pulling those changes
git pull origin abc
# if you want to simply use 'git pull' to get the changes, do the following
git config branch.abc.remote origin
git config branch.abc.merge refs/heads/abc
</pre>
<p>Alternative methods listed <a href="http://djwonk.com/blog/2009/04/18/tracking-remote-git-branches/">here</a>.
</li>
</ul>
<h2>Tags <span style="font-size: 14px; font-weight: normal; font-style: italic;"> ( Tag name is assumed to be v1.0 here )</span></h2>
<ul>
<li>
View all tags
<pre class="brush: bash; light: true; title: ;">git tag</pre>
</li>
<li>
Create a tag referencing a particular commit using its checksum (annotated)</p>
<pre class="brush: bash; title: ;">
# here commit checksum is assumed to be 98eda02.
# to view the checksum of a commit, you can do
git log --pretty=oneline
git tag -am &quot;v1.0&quot; 98eda02
</pre>
</li>
<li>
Push tags to remote repo
<pre class="brush: bash; light: true; title: ;">git push --tags</pre>
</li>
<li>
	Delete a local tag</p>
<pre class="brush: bash; title: ;">git tag -d v1.0</pre>
</li>
<li>
	Rename a local tag</p>
<pre class="brush: bash; title: ;">
	git tag NEW_TAG OLD_TAG
	git tag -d OLD_TAG</pre>
</li>
<li>
	Delete a remote tag</p>
<pre class="brush: bash; title: ;">git push origin :refs/tags/v1.0</pre>
</li>
</ul>
<p><strong>Useful Git References</strong></p>
<ul>
<li>
		<a href="http://learn.github.com">Learn.github</a>
	</li>
<li>
		<a href="http://github.com/guides/git-cheat-sheet">Github&#8217;s git cheat sheet</a>
	</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://ankitahuja.com/blog/development/git-cheatsheet/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

