<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Dmitry Churbanov</title>
	
	<link>http://www.churbanov.com/blog</link>
	<description>Keep it simple, Stupid!</description>
	<lastBuildDate>Sun, 25 Dec 2011 05:59:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/DmitryChurbanov" /><feedburner:info uri="dmitrychurbanov" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Eclipse EGit plugin, part 2</title>
		<link>http://feedproxy.google.com/~r/DmitryChurbanov/~3/RuODcTRDZbs/</link>
		<comments>http://www.churbanov.com/blog/2010/08/11/eclipse-egit-plugin-part-2/#comments</comments>
		<pubDate>Wed, 11 Aug 2010 06:03:09 +0000</pubDate>
		<dc:creator>Dmitry Churbanov</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[egit]]></category>
		<category><![CDATA[git]]></category>

		<guid isPermaLink="false">http://www.churbanov.com/blog/?p=162</guid>
		<description><![CDATA[In the <a href="http://www.churbanov.com/blog/2010/07/12/eclipse-egit-plugin/">previous post</a> we discussed how to import remote Git repository. Now let's look which Git commands are available in EGit plugin. EGit plugin is still not completely ready and does not support all Git commands. You can watch <a href="http://live.eclipse.org/node/885">"Understanding and Using Git at Eclipse"</a> webinar to learn what is ready and what the plans are.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.churbanov.com%2Fblog%2F2010%2F08%2F11%2Feclipse-egit-plugin-part-2%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.churbanov.com%2Fblog%2F2010%2F08%2F11%2Feclipse-egit-plugin-part-2%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>In the <a href="http://www.churbanov.com/blog/2010/07/12/eclipse-egit-plugin/">previous post</a> we discussed how to import remote Git repository. Now let&#8217;s look which Git commands are available in EGit plugin. EGit plugin is still not completely ready and does not support all Git commands. You can watch <a href="http://live.eclipse.org/node/885">&#8220;Understanding and Using Git at Eclipse&#8221;</a> webinar to learn what is ready and what the plans are.</p>
<p>In this post I will continue to use the same remote repository which was used in the <a href="http://www.churbanov.com/blog/2010/07/12/eclipse-egit-plugin/">previous post</a>.</p>
<h3><a name="basis-operations"></a>Basic operations</h3>
<p>In the <a href="http://www.churbanov.com/blog/2010/07/08/using-git-part-1/">first post</a> about Git we discussed the basic Git operations. Now let&#8217;s see how you can do the same using EGit plugin.</p>
<h4><a name="add-files"></a>Add files</h4>
<p>Create <code>com.churbanov.tutorial.egit</code> package and the following two classes.</p>
<pre class="brush: java; title: ; notranslate">
package com.churbanov.tutorial.egit;

/**
 * Represents workshop where different works with cars, boats
 * and other vehicles can be done.
 *
 * @author Dmitry Churbanov
 */
public class Workshop {
  public static void main(String[] args) {
    System.out.println(&quot;Welcome to our Workshop!&quot;);
  }
}
</pre>
<pre class="brush: java; title: ; notranslate">
package com.churbanov.tutorial.egit;

public class Part {
  private Long id;
  private String name;

  public Long getId() {
    return id;
  }
  public void setId(Long id) {
    this.id = id;
  }
  public String getName() {
    return name;
  }
  public void setName(String name) {
    this.name = name;
  }
}
</pre>
<p>Now we need to tell Git to start tracking just added classes. To do so, we select Part.java and Workshop.java classes in eclipse package explorer <nobr>-></nobr> Team <nobr>-></nobr> Add</p>
<p><img src="http://www.churbanov.com/blog/wp-content/uploads/2010/08/add-files.jpeg" alt="Add files to Git repository" title="Add files to Git repository" width="468" height="96" class="aligncenter size-full wp-image-185" /></p>
<h4><a name="commit-changes"></a>Commit changes</h4>
<p>To commit changes select Team <nobr>-></nobr> Commit. The &#8220;Commit Changes&#8221; window will pop up and you will need to enter commit message and select what files you want to commit or unselect the files you don&#8217;t want to commit. Press &#8220;Commit&#8221; and all the changes will be committed.</p>
<p><img src="http://www.churbanov.com/blog/wp-content/uploads/2010/08/commit-changes.jpeg" alt="Commit changes" title="Commit changes" class="aligncenter size-full wp-image-186" /></p>
<p>After commit you can see that Workshop.java and Part.java files icons are changed in package explorer.</p>
<p><img src="http://www.churbanov.com/blog/wp-content/uploads/2010/08/part-workshop-classes.jpeg" alt="Part and Workshop classes" title="Part and Workshop classes" width="282" height="128" class="aligncenter size-full wp-image-187" /></p>
<h4><a name="push-changes"></a>Push changes</h4>
<p>To push the changes to the remote repository select Team <nobr>-></nobr> Push. The current version of EGit (0.8.4) has a bug and in most cases push will not work (more is <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=317389">here</a>). There is a small workaround (see <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=317389#c2">Comment #2</a> in that bug discussion), but it still didn&#8217;t work for me on my Ubuntu 10.04. So I did it in command line. (Just after I had published this post I found that EGit doesn&#8217;t support pushing via https. More is <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=296201">here</a>.)</p>
<h3><a name="basis-operations"></a>Other useful things</h3>
<p>The other useful things which you can do with EGit are:</p>
<h4><a name="tags"></a>Tags</h4>
<p>Select &#8220;eclipse_git&#8221; project folder <nobr>-></nobr> Team <nobr>-></nobr> Tag. Enter tag name, tag message and press OK button.</p>
<p><img src="http://www.churbanov.com/blog/wp-content/uploads/2010/08/tag.jpeg" alt="Setting Tag in EGit" title="Setting Tag in EGit" class="aligncenter size-full wp-image-188" /></p>
<h4><a name="history"></a>History of a particular resource</h4>
<p>Select any resource (project, package, class, etc) <nobr>-></nobr> Show In <nobr>-></nobr> History. And you can see all the history of the selected resource in the Git repository.</p>
<p><img src="http://www.churbanov.com/blog/wp-content/uploads/2010/08/history-menu.jpeg" alt="Select EGit history menu item" title="Select EGit history menu item" width="445" height="118" class="aligncenter size-full wp-image-189" /></p>
<p><img src="http://www.churbanov.com/blog/wp-content/uploads/2010/08/history.jpeg" alt="History in EGit" title="History in EGit" width="931" height="282" class="aligncenter size-full wp-image-190" /></p>
<h4><a name="branches"></a>Branches</h4>
<p>If you want to make a branch, select &#8220;eclipse_git&#8221; project folder <nobr>-></nobr> Team <nobr>-></nobr> Branch.</p>
<p><img src="http://www.churbanov.com/blog/wp-content/uploads/2010/08/branch.jpeg" alt="Making branch in EGit" title="Making branch in EGit" width="525" height="450" class="aligncenter size-full wp-image-191" /></p>
<p>In the appeared window select &#8220;master&#8221; in the &#8220;Local Branches&#8221; category -> press &#8220;New branch&#8221; button <nobr>-></nobr> enter new branch name <nobr>-></nobr> press OK button. New branch will be created.</p>
<p><img src="http://www.churbanov.com/blog/wp-content/uploads/2010/08/creating-new-branch.jpeg" alt="Creating new branch in EGit" title="Creating new branch in EGit" width="537" height="248" class="aligncenter size-full wp-image-192" /></p>
<p>To switch to the new branch select &#8220;eclipse_egit&#8221; project folder <nobr>-></nobr> Team <nobr>-></nobr> Branch <nobr>-></nobr> select the branch you want to switch to <nobr>-></nobr> press Checkout button.</p>
<p><img src="http://www.churbanov.com/blog/wp-content/uploads/2010/08/switching-to-new-branch.jpeg" alt="Switching to new branch in EGit" title="Switching to new branch in EGit" width="525" height="451" class="aligncenter size-full wp-image-193" /></p>
<h3><a name="useful-links"></a>Useful links</h3>
<p>Using Git: <a href="http://www.churbanov.com/blog/2010/07/08/using-git-part-1/">http://www.churbanov.com/blog/2010/07/08/using-git-part-1/</a><br />
Eclipse EGit plugin: <a href="http://www.churbanov.com/blog/2010/07/12/eclipse-egit-plugin/">http://www.churbanov.com/blog/2010/07/12/eclipse-egit-plugin/</a><br />
EGit user guide: <a href="http://wiki.eclipse.org/EGit/User_Guide">http://wiki.eclipse.org/EGit/User_Guide</a><br />
Git community book: <a href="http://book.git-scm.com/">http://book.git-scm.com/</a><br />
Git reference site: <a href="http://gitref.org/index.html">http://gitref.org/index.html</a></p>
<div class="plus-one-wrap"><g:plusone size="medium" href="http://www.churbanov.com/blog/2010/08/11/eclipse-egit-plugin-part-2/"></g:plusone></div><img src="http://feeds.feedburner.com/~r/DmitryChurbanov/~4/RuODcTRDZbs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.churbanov.com/blog/2010/08/11/eclipse-egit-plugin-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.churbanov.com/blog/2010/08/11/eclipse-egit-plugin-part-2/</feedburner:origLink></item>
		<item>
		<title>Eclipse EGit plugin</title>
		<link>http://feedproxy.google.com/~r/DmitryChurbanov/~3/Q2xcybH4O4c/</link>
		<comments>http://www.churbanov.com/blog/2010/07/12/eclipse-egit-plugin/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 23:35:08 +0000</pubDate>
		<dc:creator>Dmitry Churbanov</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[egit]]></category>
		<category><![CDATA[git]]></category>

		<guid isPermaLink="false">http://www.churbanov.com/blog/?p=131</guid>
		<description><![CDATA[<img src="http://www.churbanov.com/blog/wp-content/uploads/2010/07/egit.png" alt="egit" title="egit" width="150" height="149" class="alignleft size-full wp-image-132" /> <a href="http://www.eclipse.org/downloads/">Eclipse Helios</a> (ver. 3.6) is out and <a href="http://eclipsesource.com/blogs/2010/06/22/git-support-eclipse-helios-feature-2/">the second top requested feature</a> was Git support. And here it is: <a href="http://www.eclipse.org/egit/">EGit plug-in</a>. It is still in the "<a href="http://wiki.eclipse.org/Development_Resources/HOWTO/Incubation_Phase">Incubation Phase</a>", but you already can try it.

In this tutorial I will show the basic steps of creating Java project in eclipse using EGit plug-in. Eclipse "Helios" and EGit version 0.8.4 are used in this tutorial.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.churbanov.com%2Fblog%2F2010%2F07%2F12%2Feclipse-egit-plugin%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.churbanov.com%2Fblog%2F2010%2F07%2F12%2Feclipse-egit-plugin%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><img src="http://www.churbanov.com/blog/wp-content/uploads/2010/07/egit.png" alt="egit" title="egit" width="150" height="149" class="alignleft size-full wp-image-132" /> <a href="http://www.eclipse.org/downloads/">Eclipse Helios</a> (ver. 3.6) is out and <a href="http://eclipsesource.com/blogs/2010/06/22/git-support-eclipse-helios-feature-2/">the second top requested feature</a> was Git support. And here it is: <a href="http://www.eclipse.org/egit/">EGit plug-in</a>. It is still in the &#8220;<a href="http://wiki.eclipse.org/Development_Resources/HOWTO/Incubation_Phase">Incubation Phase</a>&#8220;, but you already can try it.</p>
<p>In this tutorial I will show the basic steps of creating Java project in eclipse using EGit plug-in. Eclipse &#8220;Helios&#8221; and EGit version 0.8.4 are used in this tutorial.</p>
<h3><a name="install-egit-plugin"></a>Install EGit plugin</h3>
<p>Start eclipse. Go to Help -&gt; Install New Software&#8230;<br />
In the &#8220;Work with&#8221; select &#8220;All Available Sites&#8221;. And then in the search box enter git. You will see the following picture:</p>
<p><img src="http://www.churbanov.com/blog/wp-content/uploads/2010/07/1-Searching_egit_plugin.jpeg" alt="Searching EGit plugin" title="Searching EGit plugin" class="aligncenter size-full wp-image-133" /></p>
<p>Select &#8220;Eclipse EGit (Incubation)&#8221;:<br />
<img src="http://www.churbanov.com/blog/wp-content/uploads/2010/07/2-Selecting_egit_plugin_to_install.jpeg" alt="Selecting EGit plugin to install" title="Selecting EGit plugin to install" class="aligncenter size-full wp-image-136" /></p>
<p>Click Next. Eclipse JGit plugin will be installed automatically as a dependency of EGit plugin:<br />
<img src="http://www.churbanov.com/blog/wp-content/uploads/2010/07/5-EGit_plugin_installation_details.jpeg" alt="EGit plugin installation details" title="EGit plugin installation details" class="aligncenter size-full wp-image-137" /></p>
<p>Press &#8220;Next&#8221;, accept the terms of the licence agreement:<br />
<img src="http://www.churbanov.com/blog/wp-content/uploads/2010/07/6-Accepting_license_agreement.jpeg" alt="Accepting license agreement" title="Accepting license agreement" class="aligncenter size-full wp-image-138" /><br />
press Finish and after some time plugins will be installed. Restart eclipse. </p>
<h3><a name="import-git-repository-and-create-new-project"></a>Import Git repository and create new project</h3>
<p>After eclipse is restarted select File -&gt; Import&#8230;, and you will see the new category: Git. Expand it and select &#8220;Projects from Git&#8221;. Press next.<br />
<img src="http://www.churbanov.com/blog/wp-content/uploads/2010/07/10-Import_projects_from_git.jpeg" alt="Import projects from git" title="Import projects from git" class="aligncenter size-full wp-image-139" /></p>
<p>The next window will ask you about Git repository location. You can see two buttons there: Clone and Add. Add button should be used when you already have a local copy of Git repository. If you don&#8217;t have such copy, you need to press Clone button.</p>
<p><img src="http://www.churbanov.com/blog/wp-content/uploads/2010/07/9-Selecting_git_repository.jpeg" alt="Selecting git repository" title="Selecting git repository" class="aligncenter size-full wp-image-140" /></p>
<p>In this tutorial we will import remote Git repository, i.e. at this moment we do not have a local copy of this repository on our hard drive. The Git repository which we are going to import has been already created on <a href="http://github.com/">github</a>.</p>
<p>So, press Clone button and enter all location parameters. If you go to the github project properties, you can select what protocol are you going to use. I have selected https. Here is an example (if you just copy and past url from github to URI field all other fields, except password, should be filled out automatically):</p>
<p><img src="http://www.churbanov.com/blog/wp-content/uploads/2010/07/11-Git_repository_parameters.jpeg" alt="Git repository parameters" title="Git repository parameters" class="aligncenter size-full wp-image-141" /></p>
<p>If all parameters are correct, after pressing Next button you will see the branch selection window. In my case I do not have any branches, therefore I just press Next and select where the local copy of the Git repository will be stored. And here is the problem. You should save the copy of your Git repository in the same folder where you plan to create eclipse project. If you save Git repository in another folder, you will not be able to &#8220;share&#8221; your project with that repository. There is a solution which solves this problem, but we will talk about it later.</p>
<p><img src="http://www.churbanov.com/blog/wp-content/uploads/2010/07/13-Git_local_path.jpeg" alt="Git local path" title="Git local path" class="aligncenter size-full wp-image-142" /></p>
<p>After that select just added Git repository and press Next button:</p>
<p><img src="http://www.churbanov.com/blog/wp-content/uploads/2010/07/14-Selecting_git_repository.jpeg" alt="Selecting git repository" title="Selecting git repository" class="aligncenter size-full wp-image-143" /></p>
<p>and &#8220;Import Projects from Git&#8221; window will appear. As we are going to create new project select &#8220;Use the New Projects wizard&#8221; and press Finish.</p>
<p><img src="http://www.churbanov.com/blog/wp-content/uploads/2010/07/16-Sharing_the_imported_project.jpeg" alt="Sharing the imported project" title="Sharing the imported project" class="aligncenter size-full wp-image-144" /></p>
<p>Now we will create new Java Project using default parameters:<br />
<img src="http://www.churbanov.com/blog/wp-content/uploads/2010/07/17-Creating_Java_project.jpeg" alt="Creating Java project" title="Creating Java project" class="aligncenter size-full wp-image-145" /><br />
<img src="http://www.churbanov.com/blog/wp-content/uploads/2010/07/18-Project_settings.jpeg" alt="Project settings" title="Project settings" class="aligncenter size-full wp-image-146" /></p>
<p>and here it is:<br />
<img src="http://www.churbanov.com/blog/wp-content/uploads/2010/07/19-Java_project_with_Git_repository.jpeg" alt="Java project with Git repository" title="Java project with Git repository" class="aligncenter size-full wp-image-147" /></p>
<p>We can see the name of eclipse project (&#8220;eclipse_git&#8221;), name of Git repository (&#8220;eclipse_git&#8221;) and repository branch (&#8220;master&#8221;).</p>
<div class="plus-one-wrap"><g:plusone size="medium" href="http://www.churbanov.com/blog/2010/07/12/eclipse-egit-plugin/"></g:plusone></div><img src="http://feeds.feedburner.com/~r/DmitryChurbanov/~4/Q2xcybH4O4c" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.churbanov.com/blog/2010/07/12/eclipse-egit-plugin/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.churbanov.com/blog/2010/07/12/eclipse-egit-plugin/</feedburner:origLink></item>
		<item>
		<title>Using Git, part 1</title>
		<link>http://feedproxy.google.com/~r/DmitryChurbanov/~3/i7_99OqrNbo/</link>
		<comments>http://www.churbanov.com/blog/2010/07/08/using-git-part-1/#comments</comments>
		<pubDate>Thu, 08 Jul 2010 07:41:33 +0000</pubDate>
		<dc:creator>Dmitry Churbanov</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[git]]></category>

		<guid isPermaLink="false">http://www.churbanov.com/blog/?p=117</guid>
		<description><![CDATA[Git is a Distributed Version Control System (DVCS) (as Mercurial <a href="http://www.churbanov.com/blog/2009/12/29/working-with-mercurial-part-1/">about which I wrote earlier</a>). As well as Mercurial, Git mirrors your repository. In other words every time when you check out code you make a full backup of a repository.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.churbanov.com%2Fblog%2F2010%2F07%2F08%2Fusing-git-part-1%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.churbanov.com%2Fblog%2F2010%2F07%2F08%2Fusing-git-part-1%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Git is a Distributed Version Control System (DVCS) (as Mercurial <a href="http://www.churbanov.com/blog/2009/12/29/working-with-mercurial-part-1/">about which I wrote earlier</a>). As well as Mercurial, Git mirrors your repository. In other words every time when you check out code you make a full backup of a repository.</p>
<p>Almost all hosting web sites provide you with the possibility to use Git. One of the most widely used Git hosting web sites is <a href="http://github.com/">github</a>. Check it out.</p>
<p>There is one very good publicly available book about Git: <a href="http://progit.org/book">Pro Git</a>. This is my reference book and I advise everybody to read it.</p>
<h3><a name="lets-start-configuration"></a>Let&#8217;s start &#8211; Configuration</h3>
<p>Git comes with a git config tool. It helps you to set and get configuration parameters and control all aspects of Git. All configuration parameters can be found at three places:</p>
<ul>
<li><code>/etc/gitconfig</code> &#8211; contains global parameters for all users of your system. Gets and sets parameters if you pass <code>--system</code> option to <code>git config</code>.</li>
<li><code>~/.gitconfig</code> &#8211; contains parameters specific to current user. Works if you pass <code>--global</code> option to <code>git config</code></li>
<li><code>.git/config</code> &#8211; contains parameters specifically for the git repository you are currently using. Don&#8217;t need to pass any parameters when using <code>git config</code>. Works by default.</li>
</ul>
<p>All parameter values overwrite values on other levels, i.e. if some value for some parameter is specified in <code>/etc/gitconfig</code> file and another value for the same parameter is specified in <code>~/.gitconfig</code> file, the value from the last file will be used. The same works for values in <code>~/.gitconfig</code> and <code>.git/config</code> files. In that case the value from <code>.git/config</code> file will be used.</p>
<p>First things which you need to do is to define your identity:</p>
<pre class="brush: bash; title: ; notranslate">
$ git config --global user.name &amp;quot;Dmitry Churbanov&amp;quot;
$ git config --global user.email dmitry.churbanov@someemail.com
</pre>
<p>this code will assign git user name and email address for current user of a system. If you want to set up user name and email just for current project which you are working on right now you need to run the following code:</p>
<pre class="brush: bash; title: ; notranslate">
$ git config user.name &amp;quot;Dmitry Churbanov&amp;quot;
$ git config user.email dmitry.churbanov@someemail.com
</pre>
<p>If you want to check the value of any parameter you need to run the next code:</p>
<pre class="brush: bash; title: ; notranslate">git config parameter-name</pre>
<p> where &#8220;parameter-name&#8221; is the name of a parameter. For example, to see the name of a user or email you can check it in the following way:</p>
<pre class="brush: bash; title: ; notranslate">
$ git config user.name
Dmitry Churbanov
$ git config user.email
dmitry.churbanov@someemail.com
</pre>
<h3><a name="init-the-repository"></a>Initialise the repository</h3>
<p>To initialise git repository go to the directory where you want the repository to be placed and run:</p>
<pre class="brush: bash; title: ; notranslate">
$ git init
</pre>
<p>After this command is executed you will see <code>.git</code> subdirectory which contains all the repository files. This is the only repository where Git stores its configuration files and the history of all changes.</p>
<h3><a name="add-files"></a>Add files</h3>
<p>After you initialised the repository it does not contain any files. To tell Git to start tracking a file you first need to create it in the directory or to copy it to the directory and run:</p>
<pre class="brush: bash; title: ; notranslate">
$ git add filename
</pre>
<p>where <code>filename</code> is a name of a file to start to track. You can also run:</p>
<pre class="brush: bash; title: ; notranslate">
$ git add .
</pre>
<p>and Git will start to track all the files in the current directory and all the subdirectories which it doesn&#8217;t track at this moment. You can also use some kind of regular expression. If you want to add only .java files you need to run the following command:</p>
<pre class="brush: bash; title: ; notranslate">
$ git add *.java
</pre>
<h3><a name="making-a-commit"></a>Committing files and file states</h3>
<p>After you added some files you told Git that you want to start to keep track these files in the future, i.e. you want to include these files in your next commit command. This state of files in the Git repository is called: staged.</p>
<p>After you added all the files and are ready to make commit you need to run:</p>
<pre class="brush: bash; title: ; notranslate">
$ git commit -m &amp;quot;commit message&amp;quot;
</pre>
<p>where &#8220;commit message&#8221; is a message which goes with this commit and should describe the purpose of the commit. For example, when you fixed a bug and commit you changes you most probably will include some information which describes what bug it is or its number or something else.</p>
<p>If you just run <code>git commit</code> (or <code>git commit -a</code>) command you then will be asked to write &#8220;commit message&#8221;. It is recommended to run <code>commit</code> command without <code>-m</code> flag if your message is longer than one line. And in most cases it will and should be longer. </p>
<p>After you made commit, all files which were committed got a &#8220;committed&#8221; state. If file was committed and them modified, it got a &#8220;modified&#8221; state. So, there are three states which tracked files can have:</p>
<ul>
<li>staged &#8211; when you told to include the file in the next commit (run <code>add</code> command)</li>
<li>commit &#8211; when file was committed and was not changed after this</li>
<li>modified &#8211; when file was committed and was changed after this</li>
</ul>
<p>I wrote &#8220;tracked&#8221; earlier to point out that these are the files which Git is tracking. If file is not tracked by Git, it is called untracked. Untracked files are all files which are not tracked.</p>
<h3><a name="status-of-the-files"></a>Status of the files</h3>
<p>To check status of all files and to find their states, you need to run:</p>
<pre class="brush: bash; title: ; notranslate">
$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
nothing to commit (working directory clean)
</pre>
<p>You can see something like you see above. It means that I made commit and didn&#8217;t push my changes (push command is discussed later). Or you can see:</p>
<pre class="brush: bash; title: ; notranslate">
$ git status
# On branch master
nothing to commit (working directory clean)
</pre>
<p>which means that your local (working) copy is in the same state as a remote repository.</p>
<h3><a name="ignoring-files"></a>Ignoring files</h3>
<p>Sometimes you don&#8217;t want to include some files in the repository but you still want these files to be present in the folder. This can be some of your personal files, logs or anything else. You can say Git to ignore these files. To do so you need to create <code>.gitignore</code> file and write file names or file name patters there.<br />
For example, if you want to say Git to ignore all txt files you need to have the following in the <code>.gitignore</code> file:</p>
<pre class="brush: bash; title: ; notranslate">
*.txt
</pre>
<p>If some file matches the regular expression which is in the ignore file but you want to tell Git to keep track that particular file, you can do it in the next way:</p>
<pre class="brush: bash; title: ; notranslate">
#Text files should be ignored (this is a comment, which is ignored in the .gitignore file)
*.txt
!important.txt
</pre>
<p>In such case important.txt file will be tracked by Git, even if all .txt files are ignored.</p>
<h3><a name="diff-command"></a>Diff command</h3>
<p>When changes are made and <code>git status</code> command is executed, you can be wondered, what exactly is changed in the files which are modified. You can use <code>git diff</code> command. This command shows you what changes have been made. The following command:</p>
<pre class="brush: bash; title: ; notranslate">
git diff [path]
</pre>
<p>will show you what changes have been made in a specific file, if instead of <em>path</em> you write path to the file; or what changes have been made in all files of a specific folder if instead of <em>path</em> you write path to that folder. To see all options of <em>diff</em> command run <code>git diff --help</code>.</p>
<p><strong>One very important note:</strong><br />
If you have already added a file, say file1.txt (run <code>git add file1.txt</code>). And after that you made some changes in that file, then if you run <code>git diff file1.txt</code> you will not see the latest changes. It is because after you run <code>git add file1.txt</code>, Git cached the context of <em>file1.txt </em> file at that moment. To see cached changes you need to run :</p>
<pre class="brush: bash; title: ; notranslate">git diff --cached [path]</pre>
<p>And if you run <code>git commit</code> your latest changes will also not be committed. To add the latest changes you need to run <code>git add</code> after each modification. But there is one trick. You can use <em>-a</em> option with the <code>git commit</code> command to commit all files which were previously tracked and were modified. It allows you not to run <code>git add</code> command each time you made any change, but to run it only once.</p>
<h3><a name="removing-files"></a>Removing files</h3>
<p>If you want to remove file, i.e. to remove it from the repository (and remove it from your hard drive) you need to run:</p>
<pre class="brush: bash; title: ; notranslate">
$ git rm [path]
</pre>
<p>This command tells Git to remove file. After the next commit command this file will be removed from the repository.</p>
<p>But if you want to leave file on your hard drive and only stop to keep tracking that file, you need to run:</p>
<pre class="brush: bash; title: ; notranslate">$ git rm --cached readme.txt</pre>
<h3><a name="moving-files"></a>Moving files</h3>
<p>To move file or rename it you need to run the following command:</p>
<pre class="brush: bash; title: ; notranslate">$ git mv [file-name] [new-file-name]</pre>
<p>But it is very interesting that Git doesn&#8217;t actually track if you moved your file or not. It is somehow explicitly figures out that you renamed the file after you run something like this:</p>
<pre class="brush: bash; title: ; notranslate">
$ mv file.txt new_file.txt
$ git rm file.txt
$ git add new_file.txt
</pre>
<p>Try to run <code>git status</code> and see what happens. It is very convenient because you can rename or move file using whatever tool or program you want and them just remove and add it using Git rm and add commands.</p>
<h3><a name="help"></a>Help</h3>
<p>If you need help with any command use <code>git help [command]</code> or <code>git [command] --help</code>.  For example, to get help with commit command you need to run:</p>
<pre class="brush: bash; title: ; notranslate">$ git help commit</pre>
<p>This is it for the first post in the &#8220;Using Git&#8221; series. I think you have read pretty enough material to start using Git.</p>
<div class="plus-one-wrap"><g:plusone size="medium" href="http://www.churbanov.com/blog/2010/07/08/using-git-part-1/"></g:plusone></div><img src="http://feeds.feedburner.com/~r/DmitryChurbanov/~4/i7_99OqrNbo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.churbanov.com/blog/2010/07/08/using-git-part-1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.churbanov.com/blog/2010/07/08/using-git-part-1/</feedburner:origLink></item>
		<item>
		<title>Working with Mercurial, part 1</title>
		<link>http://feedproxy.google.com/~r/DmitryChurbanov/~3/qb9YBUYRYis/</link>
		<comments>http://www.churbanov.com/blog/2009/12/29/working-with-mercurial-part-1/#comments</comments>
		<pubDate>Tue, 29 Dec 2009 06:41:51 +0000</pubDate>
		<dc:creator>Dmitry Churbanov</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[mercurial]]></category>

		<guid isPermaLink="false">http://www.churbanov.com/blog/?p=27</guid>
		<description><![CDATA[<a href="http://mercurial.selenic.com/"><img class="alignleft size-full wp-image-115" title="Mercurial_logo" src="http://www.churbanov.com/blog/wp-content/uploads/2009/12/Mercurial_logo1.png" alt="Mercurial_logo" width="140" height="168" />Mercurial</a> is a <a href="http://en.wikipedia.org/wiki/Distributed_revision_control">distributed revision control</a> (DRC) management system. Decentralization is one of its advantages. For an individual developer DRC systems are faster than centralized: all metadata is stored locally and you do not need to contact the central server each time you modified the code. <a href="http://mercurial.selenic.com/">Mercurial</a> repository is self-contained. It means that all changes you have made will exist only in your local repository until you decide to propagate these changes to the remote one.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.churbanov.com%2Fblog%2F2009%2F12%2F29%2Fworking-with-mercurial-part-1%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.churbanov.com%2Fblog%2F2009%2F12%2F29%2Fworking-with-mercurial-part-1%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><a href="http://mercurial.selenic.com/"><img class="alignleft size-full wp-image-115" title="Mercurial_logo" src="http://www.churbanov.com/blog/wp-content/uploads/2009/12/Mercurial_logo1.png" alt="Mercurial_logo" width="140" height="168" />Mercurial</a> is a <a href="http://en.wikipedia.org/wiki/Distributed_revision_control">distributed revision control</a> (DRC) management system. Decentralization is one of its advantages. For an individual developer DRC systems are faster than centralized: all metadata is stored locally and you do not need to contact the central server each time you modified the code. <a href="http://mercurial.selenic.com/">Mercurial</a> repository is self-contained. It means that all changes you have made will exist only in your local repository until you decide to propagate these changes to the remote one.</p>
<p>This series of posts is how to start to work with <a href="http://mercurial.selenic.com/">Mercurial</a>. If you are looking for a book, there is a very good one which is publicly available: <a href="http://hgbook.red-bean.com/read/">Mercurial: The Definitive Guide by by Bryan O&#8217;Sullivan</a>. And I advise you to read it.</p>
<h3><a name="in-the-beginning"></a>In the beginning</h3>
<p>All <a href="http://mercurial.selenic.com/">Mercurial</a> commands starts from <strong>hg</strong>.The hg command provides a command line interface to the Mercurial system. In general each command has the next syntax:</p>
<pre class="brush: bash; title: ; notranslate">
hg command [options]...[arguments]...
</pre>
<h3><a name="setting-up-a-new-mercurial-project"></a>Setting up a new Mercurial project</h3>
<p>Let&#8217;s say you want to create a local repository named &#8220;repository-main&#8221;:</p>
<pre class="brush: bash; title: ; notranslate">
$ mkdir repository-main
$ cd repository-main
$ hg init
</pre>
<p><strong>init</strong> command initializes new repository in the current folder.<br />
Here is a more shorter way of creating the local repository:</p>
<pre class="brush: bash; title: ; notranslate">
$ hg init repository-main
</pre>
<p>If you check <strong>repository-main</strong> folder you can see <strong>.hg</strong> folder there.</p>
<pre class="brush: bash; title: ; notranslate">
$ ls -la
$ .
$ ..
$ .hg
</pre>
<p><strong>.hg</strong> folder is the only folder where <a href="http://mercurial.selenic.com/">Mercurial</a> keeps all repository related information.</p>
<p>But hardly ever you will create repository on you local computer. Most probably you will use one of the many  hosting services to host your repository there. One of the lists of such places you can find <a href="http://mercurial.selenic.com/wiki/MercurialHosting">here</a>.</p>
<h3><a name="working-with-existing-mercurial-repository"></a>Working with existing Mercurial repository</h3>
<p>Let&#8217;s assume you are using one of the services to host your <a href="http://mercurial.selenic.com/">Mercurial</a> repository (for this post I have used <a href="http://kenai.com">Project Kenai</a>).</p>
<p>To clone files from remote repository and create a local copy, <strong>clone</strong> command should be used:</p>
<pre class="brush: bash; title: ; notranslate">
$ hg clone ssh://dzmitryc@hg.kenai.com/project-test1~source-code-repository project-test1
no changes found
updating working directory
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
</pre>
<p>The <strong>clone</strong> command created a new directory <strong>project-test1</strong> and checked out the latest version of the default branch. In <a href="http://mercurial.selenic.com/">Mercurial</a>, the newest version of the branch is called <strong>tip</strong>. To see the logs about the newest version of the repository you can execute the <strong>tip</strong> command:</p>
<pre class="brush: bash; title: ; notranslate">
$ cd project-test1
$ hg tip
changeset:   -1:000000000000
tag:         tip
user:
date:        Thu Jan 01 00:00:00 1970 +0000
</pre>
<p>As our repository is new and empty we don&#8217;t see much info.</p>
<h3><a name="what-about-adding-new-files"></a>What about adding new files?</h3>
<p>Now lets create the file HelloWorld.java with the following content:</p>
<pre class="brush: java; title: ; notranslate">
public class HelloWorld {
  public static void main(String args[]) {
    System.out.println(&quot;Hello World!&quot;);
  }
}
</pre>
<p>We have the next in our folder <strong>project-test1</strong>:</p>
<pre class="brush: bash; title: ; notranslate">
$ ls -la
$ .
$ ..
$ HelloWorld.java
$ .hg
</pre>
<p>If we run <strong>hg status</strong> command we&#8217;ll see the following:</p>
<pre class="brush: bash; title: ; notranslate">
$ hg status
? HelloWorld.java
</pre>
<p>The <strong>status</strong> command shows the status of files in the repository. In our case we can see <strong>?</strong> (question mark) before the HelloWorld.java file. It means that this file is not tracked by the <a href="http://mercurial.selenic.com/">Mercurial</a>. The next codes are used to show the status:</p>
<pre class="brush: bash; title: ; notranslate">
M = modified
A = added
R = removed
C = clean
! = missing (deleted by non-hg command, but still tracked)
? = not tracked
I = ignored
</pre>
<p>Now if you want to tell <a href="http://mercurial.selenic.com/">Mercurial</a> to start to track the file and add it to the repository you need to execute <strong>hg add</strong> command:</p>
<pre class="brush: bash; title: ; notranslate">
$ hg add HelloWorld.java
</pre>
<p>You can check that <a href="http://mercurial.selenic.com/">Mercurial</a> is tracking just added file by executing <strong>hg status</strong> command:</p>
<pre class="brush: bash; title: ; notranslate">
$ hg status
A HelloWorld.java
</pre>
<h3><a name="commit"></a>Committing the changes</h3>
<p>To commit the changes you need to execute <strong>hg commit</strong> command:</p>
<pre class="brush: bash; title: ; notranslate">$ hg commit</pre>
<p>Just after you press Enter button <a href="http://mercurial.selenic.com/">Mercurial</a> will run a text editor and ask you to write a comment:</p>
<pre class="brush: bash; title: ; notranslate">
_

HG: Enter commit message.  Lines beginning with 'HG:' are removed.
HG: Leave message empty to abort commit.
HG: --
HG: user: dmitry@dmitry-laptop
HG: branch 'default'
HG: added HelloWorld.java
</pre>
<p>Lines started with HG will be removed. It is better to wright a good and clear comment so later you can find out what was the purpose of the commit. In our case we can wright something like: &#8220;Add new file HelloWorld.java&#8221;.</p>
<p>Another way of committing is to execute:</p>
<pre class="brush: bash; title: ; notranslate">$ hg commit -m 'Commit message'</pre>
<p>where instead of <em>&#8216;Commit message&#8217;</em> text you can write your commit comment.</p>
<p>Now if you execute <strong>hg status</strong> command you see nothing. It is because <strong>status</strong> command only shows files with which something needs to be done. Files which have already been tracked and were not changed will not be shown. After executing <strong>hg commit</strong> command all changes were saved in your <strong>local</strong> repository.</p>
<h3><a name="moving-changes-to-the-remote-repository"></a>Moving changes to the remote repository</h3>
<p>As it has been said, each local repository is a full copy of a working repository. And if you make any changes in a local repository and make commit, changes are not automatically propagated to the working repository until you decide to do so.</p>
<p>Let&#8217;s say you are fixing bugs. And every day you are fixing only one bug. And after the work was done you commit your changes to the local repository. But at the end of each week you decide to move all your changes from your local repository to the working one. To do so you need to execute <strong>hg push</strong> command:</p>
<pre class="brush: bash; title: ; notranslate">
$ hg push
pushing to ssh://dzmitryc@hg.kenai.com/project-test1~source-code-repository
searching for changes
remote: adding changesets
remote: adding manifests
remote: adding file changes
remote: added 1 changesets with 1 changes to 1 files
</pre>
<p>Our changes were pushed to the remote repository and new changeset was created.</p>
<div class="plus-one-wrap"><g:plusone size="medium" href="http://www.churbanov.com/blog/2009/12/29/working-with-mercurial-part-1/"></g:plusone></div><img src="http://feeds.feedburner.com/~r/DmitryChurbanov/~4/qb9YBUYRYis" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.churbanov.com/blog/2009/12/29/working-with-mercurial-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.churbanov.com/blog/2009/12/29/working-with-mercurial-part-1/</feedburner:origLink></item>
	</channel>
</rss>

