<?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>eXpand yOur cReativity &#187; git repo</title>
	<atom:link href="http://blog.bhushangahire.net/tag/git-repo/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.bhushangahire.net</link>
	<description>by Bhushan G Ahire</description>
	<lastBuildDate>Mon, 26 Jul 2010 10:25:25 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Setting up a new remote git repository</title>
		<link>http://blog.bhushangahire.net/2009/02/19/setting-up-a-new-remote-git-repository/</link>
		<comments>http://blog.bhushangahire.net/2009/02/19/setting-up-a-new-remote-git-repository/#comments</comments>
		<pubDate>Thu, 19 Feb 2009 08:41:31 +0000</pubDate>
		<dc:creator>Bhushan Ahire</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[git repo]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://blog.bhushangahire.net/?p=50</guid>
		<description><![CDATA[

For the impatient
Set up the new bare repo on the server:
$ ssh myserver.com
Welcome to myserver.com!
$ mkdir /var/git/myapp.git &#38;&#38; cd /var/git/myapp.git
$ git --bare init
Initialized empty Git repository in /var/git/myapp.git
$ exit
Bye!

Add the remote repository and push:
$ cd ~/Sites/myapp
$ git remote add origin ssh://myserver.com/var/git/myapp.git
$ git push origin master
Set the local master branch to track the remote branch.
Read further [...]]]></description>
			<content:encoded><![CDATA[<div class="fblike_button" style="margin: 10px 0;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.bhushangahire.net%2F2009%2F02%2F19%2Fsetting-up-a-new-remote-git-repository%2F&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;action=recommend&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe></div>
<div class="content">
<h2>For the impatient</h2>
<p>Set up the new bare repo on the server:</p>
<pre><span class="keywords">$ ssh myserver.com</span>
Welcome to myserver.com!
<span class="keywords">$ mkdir /var/git/myapp.git &amp;&amp; cd /var/git/myapp.git</span>
<span class="keywords">$ git --bare init</span>
Initialized empty Git repository in /var/git/myapp.git
<span class="keywords">$ exit</span>
Bye!
</pre>
<p>Add the remote repository and push:</p>
<pre><span class="keywords">$ cd ~/Sites/myapp</span>
<span class="keywords">$ git remote add origin ssh://myserver.com/var/git/myapp.git</span>
<span class="keywords">$ git push origin master</span></pre>
<p>Set the local master branch to track the remote branch.</p>
<p>Read further for a step-by-step explanation of what’s going on.</p>
<h2>Pre-flight sanity check</h2>
<p>Setting up a remote repository is fairly simple but somewhat confusing at first. Firstly, let’s check out what remote repositories are being tracked in our git repo:</p>
<pre><span class="keywords">$ cd ~/Sites/myapp</span>
<span class="keywords">$ git remote</span></pre>
<p>None. Looking good. Now let’s list all the branches:</p>
<pre><span class="keywords">$ git branch -a</span>
* master
</pre>
<p>Just one branch, the master branch. Let’s have a look at <code>.git/config</code>:</p>
<pre><span class="keywords">$ cat .git/config</span>
[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true</pre>
<p>A pretty bare-minimum config file.</p>
<h2>Creating the bare remote repository</h2>
<p>Before we can push our local master branch to a remote repository we need to create the remote repository. To do this we’ll ssh in and create it on the server:</p>
<pre>
<span class="keywords">$ ssh myserver.com</span>
Welcome to myserver.com!
<span class="keywords">$ cd /var/git</span>
<span class="keywords">$ mkdir myapp.git</span>
<span class="keywords">$ cd myapp.git</span>
<span class="keywords">$ git --bare init</span>
Initialized empty Git repository in /var/git/myapp.git
<span class="keywords">$ exit</span>
Bye!
</pre>
<p>A short aside about what git means by <em>bare</em>: A default git repository assumes that you’ll be using it as your working directory, so git stores the actual bare repository files in a <code>.git</code> directory alongside all the project files. Remote repositories don’t need copies of the files on the filesystem unlike working copies, all they need are the deltas and binary what-nots of the repository itself. This is what “bare” means to git. Just the repository itself.</p>
<h2>Adding the remote repository to our local git repository configuration</h2>
<p>Now that we’ve created the remote repository we’ll add it to our local repository as a remote server called “origin” using <code>git remote add</code>, which is just a nicer way of updating our config file for us:</p>
<pre>
<span class="keywords">$ git remote add origin ssh://myserver.com/var/git/myapp.git</span></pre>
<p>Let’s see what it added to the config file:</p>
<pre>[core]
  repositoryformatversion = 0
  filemode = true
  bare = false
  logallrefupdates = true
[remote "origin"]
  url = ssh://myserver.com/var/git/myapp.git
  fetch = +refs/heads/*:refs/remotes/origin/*</pre>
<p>We now have a remote repository “origin” that will fetch all of it’s <code>refs/heads/*</code> branches and store them in our local repo in <code>refs/remotes/origin/*</code> when a <code>git fetch</code> is performed.</p>
<h2>Pushing to the remote repository</h2>
<p>The time has come to push our local master branch to the origin’s master branch. We do that using the <code>git push </code> command.</p>
<pre>
<span class="keywords">$ git push origin master</span>
updating 'refs/heads/master'
  from 0000000000000000000000000000000000000000
  to   b379203bc187c2926f44a71eca3f901321ea42c6
 Also local refs/remotes/origin/master
Generating pack...
Done counting 1374 objects.
Deltifying 1374 objects...
 100% (1374/1374) done
Writing 1374 objects...
 100% (1374/1374) done
Total 1374 (delta 89), reused 0 (delta 0)
refs/heads/master: 0000000000000000000000000000000000000000 -&gt; b379203bc187c2926f44a71eca3f901321ea42c6
</pre>
<p>and that’s all, folks. Further pushes can be done by repeating the <code>git push</code> command.</p>
<p>Now you can tell your co-conspirators to:</p>
<pre><span class="keywords">$ git clone ssh://myserver.com/var/git/myapp.git</span></pre>
<p>and push and pull to your heart’s content.</p>
<h2>Track the remote branch</h2>
<p>You can specify the default remote repository for pushing and pulling using git-branch’s track option. You’d normally do this by specifying the <code>--track</code> option when creating your local master branch, but as it already exists we’ll just update the config manually like so:</p>
<pre>[branch "master"]
  remote = origin
  merge = refs/heads/master
</pre>
<p>Now you can simply <code>git push</code> and <code>git pull</code>.</p>
<h2>Sharing the remote repository with the world</h2>
<p>If you want to set it up as a public repository be sure to check out the Git manual’s chapter on <a href="http://www.kernel.org/pub/software/scm/git/docs/user-manual.html#public-repositories">public git repositories</a>.</p>
<h2>Working with remote repository branches</h2>
<p><code>git remote show</code> is used to inspect a remote repository. It goes and checks the remote repository to see what branches have been added and removed since the last <code>git fetch</code>.</p>
<p>Doing a <code>git remote show</code> at the moment only shows us the remote repo’s master branch which we pushed earlier:</p>
<pre><span class="keywords">$ git remote show origin</span>
* remote origin
  URL: ssh://myserver.com/var/git/myapp.git
  Tracked remote branches
    master</pre>
<p>Let’s create a new local git repository and push to a new branch on the remote repository. We can then use <code>git remote show</code> to see the new remote branch, <code>git fetch</code> to mirror it into our local repo and <code>git checkout --track -b</code> to create a local branch to do some work on it.</p>
<p>We’ll start by creating a new local repo and pushing some code to a new branch in the remote repository.</p>
<pre><span class="keywords">$ mkdir /tmp/other-git</span>
<span class="keywords">$ cd /tmp/other-git</span>
<span class="keywords">$ git init</span>
Initialized empty Git repository in /tmp/other-git
<span class="keywords">$ git remote add origin ssh://myserver.com/var/git/myapp.git</span>
<span class="keywords">$ echo "Rails 2... woo" &gt; afile</span>
<span class="keywords">$ git add afile</span>
<span class="keywords">$ git commit -m "Added afile" </span>
Created initial commit 0ac9a74: Added afile
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 something
<span class="keywords">$ git push origin master:refs/heads/dev/rails-2</span>
updating 'refs/heads/rails-2' using 'refs/heads/master'
  from 0000000000000000000000000000000000000000
  to   0ac9a7457f4b21c9e058d4c54d262584bf35e528
 Also local refs/remotes/origin/rails-2
Generating pack...
Done counting 3 objects.
Deltifying 3 objects...
 100% (3/3) done
Writing 3 objects...
 100% (3/3) done
Total 3 (delta 0), reused 0 (delta 0)
Unpacking 3 objects...
 100% (3/3) done
refs/heads/rails-2: 0000000000000000000000000000000000000000 -&gt; 0ac9a7457f4b21c9e058d4c54d262584bf35e528
</pre>
<p>Now let’s switch back to our old git repository and see if it detects the new branch on the remote repository:</p>
<pre><span class="keywords">$ git remote show origin</span>
* remote origin
  URL: ssh://myserver.com/var/git/myapp.git
  New remote branches (next fetch will store in remotes/origin)
    dev/rails-2
  Tracked remote branches
    master
</pre>
<p>Let’s update our mirror of the remote repository by doing a <code>git fetch</code>:</p>
<pre><span class="keywords">$ git fetch</span>
* refs/remotes/origin/master: storing branch 'dev/rails-2' of ssh://myserver.com/var/git/myapp.git
  commit: b379203
<span class="keywords">$ git remote show origin</span>
* remote origin
  URL: ssh://myserver.com/var/git/myapp.git
  Tracked remote branches
    master
    dev/rails-2</pre>
<p>We should now be able to see this in a our list of remote branches:</p>
<pre><span class="keywords">$ git branch -a</span>
* master
origin/dev/rails-2
origin/master</pre>
<p>If we then wanted to do some work on this remote <code>dev/rails-2</code> branch we create a new local tracking branch like so:</p>
<pre><span class="keywords">$ git checkout --track -b dev/rails-2 origin/dev/rails-2</span>
Branch dev/rails-2 set up to track remote branch refs/remotes/origin/dev/rails-2.
Switched to a new branch "dev/rails-2"
</pre>
<p>To keep up-to-date and push new changesets we simply use <code>git push</code> and <code>git pull</code> when working in the local <code>dev/rails-2</code> branch.</p>
<p>Also notice, like we manually changed for master, <code>.git/config</code> has a new entry for this new tracking branch:</p>
<pre>[branch "dev/rails-2"]
  remote = origin
  merge = refs/heads/dev/rails-2
</pre>
</div>
<div class="content">Reference from <a href="http://toolmantim.com/articles/setting_up_a_new_remote_git_repository">http://toolmantim.com/articles/setting_up_a_new_remote_git_repository</a></div>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-center">
<ul class="socials">
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://blog.bhushangahire.net/2009/02/19/setting-up-a-new-remote-git-repository/&amp;title=Setting+up+a+new+remote+git+repository" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://blog.bhushangahire.net/2009/02/19/setting-up-a-new-remote-git-repository/&amp;title=Setting+up+a+new+remote+git+repository" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://blog.bhushangahire.net/2009/02/19/setting-up-a-new-remote-git-repository/&amp;title=Setting+up+a+new+remote+git+repository" rel="nofollow" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://blog.bhushangahire.net/2009/02/19/setting-up-a-new-remote-git-repository/" rel="nofollow" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://blog.bhushangahire.net/2009/02/19/setting-up-a-new-remote-git-repository/&amp;t=Setting+up+a+new+remote+git+repository" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=Setting+up+a+new+remote+git+repository+-+http://tr.im/SURM+(via+@bhushangahire)" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://blog.bhushangahire.net/2009/02/19/setting-up-a-new-remote-git-repository/&amp;title=Setting+up+a+new+remote+git+repository&amp;summary=%0AFor%20the%20impatient%0ASet%20up%20the%20new%20bare%20repo%20on%20the%20server%3A%0A%24%20ssh%20myserver.com%0AWelcome%20to%20myserver.com%21%0A%24%20mkdir%20%2Fvar%2Fgit%2Fmyapp.git%20%26amp%3B%26amp%3B%20cd%20%2Fvar%2Fgit%2Fmyapp.git%0A%24%20git%20--bare%20init%0AInitialized%20empty%20Git%20repository%20in%20%2Fvar%2Fgit%2Fmyapp.git%0A%24%20exit%0ABye%21%0A%0AAdd%20the%20remote%20repository%20and%20push%3A%0A%24%20cd%20%7E%2FSites%2Fmy&amp;source=eXpand yOur cReativity" rel="nofollow" title="Share this on Linkedin">Share this on Linkedin</a>
		</li>
		<li class="sexy-tumblr">
			<a href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fblog.bhushangahire.net%2F2009%2F02%2F19%2Fsetting-up-a-new-remote-git-repository%2F&amp;t=Setting+up+a+new+remote+git+repository" rel="nofollow" title="Share this on Tumblr">Share this on Tumblr</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

<div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://blog.bhushangahire.net/2009/02/19/setting-up-a-new-remote-git-repository/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
