First create a repo on any machine. If you already have one, use it. Otherwise use
cd ~/myproject git initand then maybe check in some files:
echo 'hello' > foo git add foo git commit
Next create a bare repo clone of the existing repo:
cd ~/myproject/.. git clone --bare myproject myproject.gitthis creates the directory myproject.git from the existing depot myproject/.git
Now copy myproject.git to the server. Choose a directory for it to live in (e.g. /src/mygit):
ssh <user>@<server> mkdir -p /src/mygit scp myproject.git <user>@<server>:/src/mygit/myproject.git
That's it! Now to clone the repo go to a fresh dir on any machine use
cd ~ mv myproject myproject.old git clone <user>@<server>:/src/mygit/myproject.gitThis will create a new ~/myproject directory fully populated. As a sanity check diff the new and old dirs:
ddiff myproject myproject.oldIf they are identical (or the old one does not contain anything useful that is nt in the new) then you can delete the old myproject.old directory.
To get the latest changes from the server:
cd ~/myproject git pullor
git fetchor
git fetch origin
To push all changes from the local master branch back to the server's master branch:
cd ~/myproject git push origin master
If you will give some people read access and other people write access you should create a group for write access permission.
sudo groupadd gitgroup
cd /src/mygit echo "chgrp --preserve-root --quiet -R gitgroup /src/mygit" >> hooks/post-receive echo "chmod --preserve-root --quiet -R g+rw /src/mygit" >> hooks/post-receive
cd /src/mygit chgrp -R gitgroup . chmod -R g+rw .
To give someone access to git on a server:
sudo useradd -mN -s /usr/bin/git-shell gituser
sudo su gituser -s /bin/bash cd mkdir -p .ssh cat rsa.pub >> .ssh/authorized_keys exit
sudo mkdir -p /src/mygit sudo chown <yourself>:<yourself> /src/mygit # now as user <yourself> do: cd /src/mygit git clone --bare /location/of/git/repo/to/copy /src/mygit
This should give them read-only permission. (To grant read/write permission see below.)
Add as many keys to the ~gituser/.ssh/authorized_keys as you want - one (or more) for each person with access. They can now clone from
git clone ssh://gituser@apooley-6/src/mygit
Create a group for write access (see above).
Add the user to the group:
sudo usermod -a -G gitgroup gituser