1

I have all my code/projects as repos in github. I use git a lot, I do have few projects which I cannot push to github at the same time, I want to keep a backup on my External Hard drive, is there any existing software where you can turn your external harddrive into a repo where I can just git push and the code gets pushed to the repo on my harddrive?

This makes it really easy to push when you are working and keep a backup.

Simple put, Git hub locally on a harddrive. Thats it.

If it does not exist, how to get started on this and write my own software ? Give your insights.

2

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.

  • You don't need to use ssh to localhost. Git supports the file:// protocol (in fact, you can skip the protocol and just specify the path). – muru Aug 31 '14 at 8:55
  • @muru Feh. It's 2AM here, and this allows you to host it as a servlet if need be. More customizable. -Edited- – Kaz Wolfe Aug 31 '14 at 8:56
  • @muru Better now? – Kaz Wolfe Aug 31 '14 at 9:04
  • Indeed. One can set up the SSH+user things any time, since the bare repo works no matter how you access it. So setting up all this until the friends actually do come to play is over-engineering. +1, now. – muru Aug 31 '14 at 9:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.