Cloud based source control systems such as github are a great addition to the everyday toolkit of the software engineer. However, what if you want to host your own local git repository? Maybe for security, budget limitations of just personal preference?
This post will explain how you can do just that. During this explanation I am using Debian 7, but it should work on other operating systems too.
Let’s get started.
1. Install git
sudo apt-get install git
2. Create a directory. The name does not matter at this point, since this will only be a temporary directory. I named mine ‘git_project’ and stored it in my home folder.
cd ~ mkdir 'git_project'
3. Now initialise the temp folder as a repository.
cd ~/git_project git init
4. Now copy the files you want to initialise the repository with into this temp directory. If you plan to add files later, just create a temp file.
cd ~/git_project touch initial.temp
5. Now add all the files in the repository.
git add *
6. Next, commit the files as the initial commit.
git commit -m 'Initial Commit'
7. Now set it to a bare repo. This means that only the bare git repository will be stored, and not the source code files.
git config --bool core.bare true
8. Now move the hidden git file to your central repository location (I store mine in ~/repo). At the same time give it a project name.
mv .git ~/repo/myproject.git
9. You can now clone this repository using the command line.
git clone email@example.com:/home/user/repo/myproject.git
That’s it. In a future post I’ll explain for you can integrate this with an IDE.