$ cat "

Set Up Shared and Local Git Repository


In my current hobby project I'm using git with a shared repository on an external hard drive, and a local repository on my primary disk.

To set up an empty shared repository, use the following command:

git init --bare --shared

This tells git to create a shared repository that is not supposed to have a working copy of the code, just to be pushed to and pulled from.

You then clone the shared repository on your primary disk by executing the git clone command:

git clone /path/to/shared/repository

You will get a warning about that you have cloned an empty repository, but that isn't a problem.

Now you are all set to add your first file and do your first commit in the new repostiory. For example:

touch todo.txt
git add .
git commit -m 'Added todo list'

You now have something that you can push to the shared repository. If you try to push your commits to the shared repository using

git push origin

you will get an error message saying No refs in common and none specified; doing nothing; Perhaps you should specify a branch such as 'master'. This is because of that the remote repository is completely empty, and has no branches. To push your commits you have to explicitly specify the name of the branch, i.e. master.

git push origin master

Now you have pushed your first commits to the remote repository and you can now push and pull like nobody's business.

Written by Erik Öjebo 2010-09-09 20:15