Into The (Local) Cloud!
I, and I’m sure many of you use Github. If not, and you care to get started, I’ve written about this before. However, sometimes you don’t want to work in the open. If this is the case, then you likely aren’t going to be using Github. Sure, you can pay for private repos, or you can use alternatives like Bitbucket that provide free private repos. Personally, I prefer to keep my private things out of The Cloud (TM).
I have a headless computer hooked up to my home network running Debian that I use as a file server. I find it convenient to have my various projects that aren’t on Github in git repositories on my server. It provides a backup, and makes it easy to keep my desktop and laptop in sync. So, let’s talk about that.
Making The Repository
This is a pretty straightforward process. Much like the usual ways of making a local repository, we’ll be using
git-init, however, we need to create a bare repository, otherwise we’ll have issues pushing and pulling. To do this, enter the following in the directory on the server where you want the repository to live:
git init --bare [repo_name]
[repo_name] is the name of the repository. A folder with this name will be created in the current directory.
This repository is special; you cannot work directly in it, you must clone and use push/pull.
Meanwhile, on Our Workstation
Back on the machine where we’ll be working, we first need to clone our newly created repository:
git clone [username]@[server]:[path_to_repo]
[username] is your user on the server that has SSH access,
[server] is the IP address or hostname of the server, and
[path_to_repo] is the location of the repo on the server. When you do this, you’ll get a warning about cloning an empty repo which you can ignore. After all, of course it’s empty, you just made it!
…and guess what? That’s all there is to it! You can push and pull as normal at this point, and should be ready to go.
But DMP Guy, I Already Have A Repo!
So, you already got a repo, and you want to move it to a central server? This isn’t much more difficult. First, get the repo itself to the server somehow. I recommend SFTP:
sftp [username]@[server] sftp> put [compressed_repo] sftp> bye
[username] is an account and
[server] is the server and
[compressed_repo] is your repo directory compressed in your favorite manner.
After this is done, ssh to the server, then find and uncompress the repo. Next we make a bare repo out of it:
git clone --bare [orig_repo] [bare_version]
[orig_repo] is the original repo that you just extracted, and
[bare_version] is the name you want to give the new bare version. After this is done, you can
rm -rf [orig_repo], and then clone and use
[bare_version] as described above.