Last week…
- Jason
- I started using Unfuddle for [redacted]
- I like it so far.
- Trey
- it’s a good service
- I’m going to move all my private repos there
- Jason
- if you just want online repo storage, why not just use your Slice?
- Trey
- I should do that
- Jason
- It’s super easy
- Trey
- yeah?
- you should blog it
- Jason
- ok.
So here is how to get your remote git up and go
Setting up a remote Git repo and connecting via ssh in a nutshell:
First, we install git on the server. I’m using aptitude on Ubuntu for this. Next, we have two options: we can just set up a bare git repo and push to it using an existing user; or, if we want to be able to safely share the repo with others, we can set up a git user. After setting up the git user, we create the bare git repo, chown it to the git user, and push to it from our local machine.
On your slice…
Install Git
sudo aptitude git-core
Add the Git User (If you want to use an existing user, skip to step #7.)
sudo adduser git
Set up ssh key (standard procedure)
su - git mkdir .ssh chmod 700 .ssh nano -w ~/.ssh/authorized_keys
(Yes, I use nano. What of it?)
[ paste in public key and save the file ]
Exit su
exit
Give the Git User a special shell that only allows git commands
sudo nano /etc/passwd
[ Change git’s shell from
/bin/sh
to/usr/bin/git-shell
][ Save /etc/passwd ]
If you have set up your sshd_config to only allow specific users, you’ll need to add git
sudo nano /etc/ssh/sshd_config
[ Add git to AllowUsers (near the end of the file), e.g.: AllowUsers jason git ]
Reload sshd
sudo /etc/init.d/ssh reload
Create a dir for your repos
sudo mkdir /var/git
sudo chown `whoami` /var/git
Create your first bare repo (
--bare
means no working dir; i.e. just the contents of .git)cd /var/git mkdir test.git cd test.git git --bare init sudo chown -R git .
Back on your local machine…
Go to there
cd /path/to/test
Add your remote (just as if it were somewhere like Github)
git remote add origin ssh://git@slice1.example.com/var/git/test.git
Push all your branches
git push --all
N.B.
- If you use something other than Ubuntu and aptitude, your git-shell may be located somewhere else. Try which git-shell to find it.
- If you’ve changed your ssh port to something other than 22, you’ll need to do something like this: git remote add origin ssh://git@slice1.example.com:8822/var/git/test.git
- To allow others to contribute, put their public key in
/home/git/.ssh/authorized_keys
, but remember, you can’t log in as git; so, you’ll need to edit it as root with sudo.
Questions? Comments? Recommendations? Let me know.
Feb 8th, 2009 at 10:19 pm Trey Piepmeier
Great writeup, Jason.
Now put repo in the
~/bin
directory of your slice and you can just typerepo whatever
. Then put slicerepo somewhere on the path of your local machine and typeslicerepo whatever
to setup the remote origin for the existing repository.Feb 8th, 2009 at 10:32 pm Jason Johnson
Thanks, Trey. Nice shortcuts.
Dec 23rd, 2010 at 9:43 pm Woodrow "asim" Jarvis Hill
Thanks for this; your instructions (along with some tweaks for a Win32 system) were awesome! I’ve been using git locally for awhile, and with my new PC, it was time to use one repository for all coding — as well as other projects. :)