Installing Git on a server (Ubuntu or Debian)

Installing Git on a server (Ubuntu or Debian)

From: http://www.hackido.com/2010/01/installing-git-on-server-ubuntu-or.html

I'm shutting down my old blog for good soon.. This is one of the last popular articles from that blog (from July 2008) that is still relevant. I haven't followed these directions in a while but they should still work. YMMV:

There are lots of great instructions out there for using Git so you may not be interested in another one. Mine is no doubt imperfect as well, but I didn't find a front-to-back tutorial for getting rolling with Git on your own centralized server. I ended up cobbling information together from a bunch of sources (which I will list below). Mostly for my own benefit, I'm posting what I learned here. Feel free to ignore or read on as you desire.. By the end of it we'll have installed Git on a server, created a repository on that server, and checked in code from our local machine.







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. Seethis link for OS X if you don't have Mac Ports.



sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install git-core


Step 2: Set up the server. We'll have to do some work on the server. We're going to useGitosis 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:



sudo apt-get install python-setuptools


Step 3: Gitosis. Now it's time to get Gitosis. For the most part I followed theinstructions 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.


mkdir ~/src
cd ~/src

git clone git://eagain.net/gitosis.git
or
git clone https://github.com/tv42/gitosis.git

 


Install it using the python setup tool we grabbed earlier.



cd gitosis
sudo python setup.py install


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!



sudo adduser \
  --system \
  --shell /bin/sh \
  --gecos 'git version control' \
  --group \
  --disabled-password \
  --home /home/git \
  git


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. Seeinstructions 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:



sudo -H -u git gitosis-init < /tmp/id_rsa.pub


You'll see output like this:



Initialized empty Git repository in ./
Initialized empty Git repository in ./


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:

sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update


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



git clone git@YOUR_SERVER:gitosis-admin.git

fatal: 'gitosis-admin.git' does not appear to be a git repository

solve:


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:



[group myrailsapp]
members = vince@urbanpuddle
writable = myrailsapp


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.



 
git commit -a -m "created a new repository!"
git push


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.



cd myrailsapp
git init


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:



.DS_Store
log/*.log
tmp/**/*
config/database.yml
db/*.sqlite3


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..



git remote add origin git@YOUR_SERVER:myrailsapp.git


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.



git add .
git commit -a -m "initial import"
git push origin master:refs/heads/master


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.



git clone git@YOUR_SERVER:myrailsapp.git


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:




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



sudo apt-get install gitk


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值