For the past 1 month, especially en-route preparations for FOSS.IN 2009 I wanted to have a complete repository on my hard disk from where people can checkout, commit src code, schematics, technology information and do whatever needed without the necessity of INTERNET connectivity. Thats where git drew my attention. I have been a cvs / svn user for long time now and the very fundamental design aspect of git / any distributed version control system makes me happy as it is just what a developer like me needs.
So here goes a quick how-to (more of a note to self) on how I setup a remote git repo on one of the servers I have ssh access to.
1. SSH into your remote server (ssh uname@remoteserver)
2. Say, you are starting off setting up a git setup on this remote server. Create a directory by name say git (In the below example I put it in the home directory). All projects shall go into this directory.
uname@remoteserver$ mkdir ~/git
3. Now, create a project.git directory. If your project name is ledblink then do the following.
uname@remoteserver$ mkdir ~/git/ledblink.git
4. Initialise a bare git directory
uname@remoteserver$ cd ~/git/ledblink.git
uname@remoteserver/git/ledblink.git$ git – -bare init
5. Edit the description file to describe the project [Optional of-course]. Then edit the config file to enable reposharing by adding the line “sharedrepository = 1” under the [core] section.
6. Setup appropriate permissions. In the below example user only rights.
uname@remoteserver/git/ledblink.git$ chmod -R g=u .
uname@remoteserver/git/ledblink.git$ find . -type d | xargs chmod g+s
So all is done on the server side. Go back to your local machine.
7. Go to the folder you want to be version control or create a fresh directory where you will put your project files. Lets say localprojectrepo is the directory name. Change directory into the localprojectrepo and do the following.
uname@localhost/localprojectrepo$ git init
uname@localhost/localprojectrepo$ touch samplefile.txt
uname@localhost/localprojectrepo$ git add .
uname@localhost/localprojectrepo$ git commit -m “First commit”
Your local git repository is created. Now lets add the server as remote so that a push “syncs” the changes to the remote server.
uname@localhost/localprojectrepo$ git remote add origin uname@remoteserver:<pathto>/git/ledblink.git
uname@localhost/localprojectrepo$ git push origin master
Life is good! To take backups of your remote git repo, use your favourite means to copy the ~/git directory you create on the remote server. Thanks to good old friend Anurag for helping me through the details.