Installing Git on a server

Step 1: Install Git. You'll have to do this ON BOTH YOUR SERVER AND LOCAL MACHINE. If you're running a different OS for your client find and check out instructions for installing git on that OS instead. See this link for OS X if you don't have Mac Ports.



Step 2: Set up the server. We'll have to do some work on the server. We're going to use Gitosis which needs python and a python setup tool to get running. Grabbing the python setup tool in Debian/Ubuntu will grab all the requirements if you don't already have them:



Step 3: Gitosis. Now it's time to get Gitosis. For the most part I followed the instructions on scie.nti.st, so full credit and many thanks to them. Once you're done with my instructions, I recommend you go visit them and read more details on adding users and some other advanced topics.

From your home directory on your server, create a new directory called src, and from there grab the gitosis code.



Install it using the python setup tool we grabbed earlier.



Step 4: Setup some security. We're next going to add a new user called git. This is the guy that will do all the heavy lifting for us!



IMPORTANT: If you have locked down ssh, don't forget to go into your /etc/ssh/ssh_config file and add git to the list of Allowed Users that can login. That list of users is separated by a space not a comma.

I always encourage the use of public/private key exchange and in the case of gitosis it looks to be required. Generate a key if you haven't already. See instructions for public/private key here. I'm going to assume that from this point on you can access your server from your local machine using a public key exchange!

Next, copy your id_rsa.pub file over to your server somewhere (in our example we're using /tmp) and then run this command:



You'll see output like this:



Others have reported seeing that 3 times but when I did it on Ubuntu Hardy Heron I only saw it twice.

Step 5: Minor permissions tweak. Just in case, let's make sure permissions are set correctly:



We're now done with the server config! From your local machine, test it out with this:



If all went well you have a gitosis-admin directory with a gitosis.conf file and keydir directory. We're basically setup now. We just need to create a new repository and push it to the server.

Step 6: Configure gitosis for a new rails project. Use your favorite editor to create a new block under the gitosis one. It should look like this:



A couple of things to watch out in the above block. First, make sure your name matches what's in your public key (that is, open your id_rsa.pub file and see that what the name says. Mine says vince@urbanpuddle so that's what I have above. Yours will be different.) Second, make sure you spell writable correctly!

Once you're done, commit and push the changes up to the server.

 


What we've basically done in this step is configured gitosis to accept a new repository. We then submitted that new configuration to the server using Git itself. Genius!

Step 7: Put your local code under version control. Now that the myrailsapp project is waiting for us on the server let's go put it under version control on our local machine.



As you may have heard, most of the goodness with git is in a special hidden .git directory at the root of your project. That's pretty cool since it means removing your project from version control is as simple as erasing that directory. Way easier than subversion.. especially if something goes wrong..

If you're a Rails developer you may want to blacklist some things from being under version control. Open up a text editor and create a file called .gitignore in the root of your project directory. Fill it up with this goodness:



Thanks to Ryan Bates for the above. If you haven't checked out Railscasts 96 you should do that as well. There's good info on creating empty files in a few empty directories to make sure they're under version control.

Step 7.5: Designate the server as a remote repository. An interim step here is to remote add the files to the server we set up previously. Honestly I'm not sure what's going on here under the covers but it's necessary..



Step 8: Add files and commit! Let's add everything to git, (note the trailing dot) and then push your initial commit to the server.



Once that's done you're done! You can grab your code from any place that has public key access to your server using this command.



Again, please please go check out this post which was the inspiration for 90% of what you just read. They did a great job and go into more detail in some spots than I did. You'll also likely find questions and answers to any errors you encounter on the way there.

Also, as promised here are some resources:

    * scie.nti.st
    * Railscast 96
    * Peepcode

Last thing , if you're on Debian or Ubuntu and follow the Peepcode, keep in mind you'll need to separately install gitk.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值