GitHub Micro-Server Method
To do this, you will need a public key. Info on generating one can be found all over the internet. Do that now. You'll need it in a sec. You will also need the openssh-server
package installed.
First off, you need to prepare the environment for Git. To do this, you need to make a user.
sudo adduser git
su git
cd
mkdir .ssh
This user will do all of the Git functions. You're gonna need your public key here. Simply run:
cat /path/to/your/public/key.pub >> ~/.ssh/authorized_keys
chmod -R go= ~/.ssh
Now, you have SSH and the Git user completely set up. Now, we need to make a Git project. To do this, run these commands (still as Git user):
cd ~
mkdir git
cd git
mkdir project.git
cd project.git
git --bare init
You must shell in and do the above commands everytime you want to make a new repo. More details later. I promise!
Now you have a working Git server you can connect to! You can do all the fun stuff you like doing with Git now!
cd myproject
git init
git add .
git commit -m 'initial commit'
git remote add origin git@localhost:/home/git/git/project.git
git push origin master
You can of course invite other people on your local network to use this Git server, as long as they connect with your local IP instead of localhost
.
Now, one project is most likely not enough for you. Fortunately there's a simple way to add/remove repos. Run the following commands:
su git
cd ~/git
mkdir project_name.git
cd project_name.git
git --bare init
Then, just connect to the other Git repo when you need to. It's all just changing variables!
You can also (if you want) have a web interface to Git. Info is available from the GitHub official source.
Source for this guide: git-scm.com -- It is a great place for learning how to start a Git server. Start from 4.4 (linked) and move onwards.
file:///
URI Method
Feh. As @muru pointed out in a comment, Git supports the file:///
URI. Here is a way to do it with no users, but no more micro-server in case your friends come over to play.
As you:
cd ~
mkdir .git-projects
cd .git-projects
mkdir project.git
cd project.git
git --bare init
To connect:
cd myproject
git init
git add .
git commit -m 'initial commit'
git remote add origin file:///home/user/.git-project/project.git
git push origin master
I personally like the microserver better. You can move it easier, esp. if you get a VPS.
Final Comments
The SSH server method does not allow you to save to an external hard drive (easily), but the file:///
method does. Just change the paths!
You could, theoretically, make the "git" user's home on the external hard drive, but that might cause more troubles than good.
Best Answer
The answer to both of your questions is no, you can create any directory you want in the
/
. the only thing that could happen is some permission issues with some spacial paths I guess.However it's better to store the
.git
directory somewhere else, something look like:Read here.