How to create a central git repository

I’ve been working a lot with git lately and one of the problems I had was to create a central git repository that two people could push and pull to. It’s a simple problem, and it’s got a simple solution. Run this in a terminal:

mkdir code; # Make an initial working directory
cd code;
git init;

Now add some files, and run “git add” on them. Then commit.

echo "Hello git!" > testfile;
git add testfile;
git commit -am 'first commit';

The next thing you want to do is creating the “central” repository. You do this by cloning your current working directory with the “–bare” flag:

cd ..;
git clone --bare code central;

The working directory does not yet know of this central directory called “central”. To fix this, one could either go through the config for the folder or just make a clone of the central directory. We will do the latter, and therefore we will not need the current “code” directory.

rm -Rf code;
git clone central code; # make new coding dir

All done! You can now edit files in “code” and run “git push” or “git pull” as you like. Good luck!

Share Button

Leave a Reply

Your email address will not be published. Required fields are marked *