From subversion to git (part1 – git)
You read it everywhere – obviously git must be the best since sliced bread. But replacing subversion with git is not exactly just as easy as one would hope. Installing git itself is simple. On Ubuntu just have to install the “git-core” package. But I would recommend some other packages as well.
apt-get install git-core git-svn gitweb
Done. You can already use git and push a git repository onto the server via ssh protocol. You would only need to expose the directory via http. If you want shared repository with permission administration you will need a slightly more complex setup. At least if you don’t want to hand out ssh account for every person. So I’d suggest you create your repository directory in the home directory of a separate “git” user
sudo adduser \ --system \ --shell /bin/sh \ --gecos 'git version control' \ --group \ --disabled-password \ --home /home/git \ git sudo -u git mkdir /home/git/repositories
Copy your public ssh key onto the machine as “/home/git/.ssh/authorized_keys” and you should be able to log into the machine with “ssh [email protected]”.
In order to make the repositories available we now start the git daemon.
sudo -u git git-daemon --reuseaddr \ --verbose \ --base-path=/home/git/repositories/ \ --detach
There is also a package called “git-daemon-run” to start the daemon on system start. Frankly speaking I found it way too complicated and just created a simple init.d script that does the trick.
sudo cat > /etc/init.d/git-daemon << EOF #!/bin/sh test -f /usr/bin/git-daemon || exit 0 . /lib/lsb/init-functions GITDAEMON_OPTIONS="--reuseaddr --verbose --base-path=/home/git/repositories/ --detach" case "$1" in start) log_daemon_msg "Starting git-daemon" start-stop-daemon --start -c git:git --quiet --background \ --exec /usr/bin/git-daemon -- ${GITDAEMON_OPTIONS} log_end_msg $? ;; stop) log_daemon_msg "Stopping git-daemon" start-stop-daemon --stop --quiet --name git-daemon log_end_msg $? ;; *) log_action_msg "Usage: /etc/init.d/git-daemon {start|stop}" exit 2 ;; esac exit 0 EOF update-rc.d git-daemon defaults
Once started you can create a new project
cd testproject git init git add . git commit -m "initial import" git remote add origin [email protected]:repositories/testproject.git touch .git/git-daemon-export-ok scp -rp .git [email protected]:repositories/testproject.git git push --all
which pushes the initial project to the git server via ssh protocol. The “git-daemon-export-ok” makes it accessible to the outside world via git daemon. Now everyone can clone the repository which is the initial checkout and the first step to follow your work.
git clone git://yourserver.com/testproject.git
Now let’s also expose the git repository over http similar to viewvc…