Hosting your own git repos
Hope this helps you out. I wasn't a huge fan of github even before it became owned by Microsoft. These days I think there are enough reasons to host your own git repos. It's honestly pretty simple an free. I think I first started questioning hosting all of my cli/projects at github when their site came under a state sponsored DDoS attack. We were a small SaaS startup with a dev heavy staff. During this attack the whole office stopped pretending to work and actually just blatantly started goofing off.
After that DDoS I started looking for github alternatives and figured out that you can use git itself to just host your own repos. So these days I keep my own gitserver at Digital Ocean. This allows me to control my own uptime and not leave my repos out there for Microsoft to do whatever they want with it.
In a nutshell this is my setup. gitshed is hosted at DigitalOcean and I use my default Debian SSH setup as the base for connectivity. I also took a lot of the steps from Learn Enough GIT I love the Learn Enough courses to get you off the ground. But I did have to modify the methods a bit so I wasn't using github as my repo.
Build a VPS
Step 1: Go setup a VPS and then well get to working on Git
Go to your favorite hosting provider as I mentioned, I use Digital Ocean, but you can use AWS, Google, or whomever. I prefer Debian 12.x these days, but you can probably make this work with other versions of Linux or anything you can get git to compile on. I went with a small low cost droplet $6/month I will just grow the droplet if I need it. Once the VPS is setup walk through the basic Debian SHH/Setup to add user accounts and firewall configs.
Step 2: Installing Git
Install git, I just used the default git install from the apt repositories. Be sure you install this on all of your devices (gitshed, home_pc, and laptop)
sudo apt install git
There are a ton of git related tools in the default Debian apt repos but this should be all you need to get started.
I guess this is a good time to point out in Linux and in most things software/commercial hardware there are a lot of ways to do things. In my case I am the only person using my repos, I am not setting this up for multiple users but you can do a couple of tricks with building a git user/service account and let multiple users push/pull cli from that directory. If I went that far I would probably enforce individual user accounts. But like I said a lot of ways to do things.
With that being said lets get on to step 3
Step 3: Setting up local repos
Now on my home_pc or laptop I just use my home directory because that is where I keep most of my coding projects. I mean why in the world would I keep it in var or opt? (sorry bad nerd joke). You can name the projects how ever you'd like I just usually go with something like repos, projects, or cli. Under that directory is where I keep all of the different projects I am working in here we just call it repo1 and repo2
[laptop]$ mkdir repos [laptop]$ cd repos [laptop]$ mkdir repo1 repo2
Now in the repos directory you can initialize the repository
[laptop]$ cd /home/nugget/repos/repo1 [laptop]$ git init Initialized empty Git repository in /Users/nugget/repos/repo1/.git/ [laptop]$
This will give you an empty git repository on your local machine. Now you can load your cli or whatever into this directory. For the case of this example we will just touch an empty file and add a comment.
[laptop]$ touch demo_file.txt
Now you can commit the file to your local repo. You can use other methods this is just to get us through the demo.
[laptop]$ git add -A [laptop]$ git commit -m "Initialize repository" [main (root-commit) 334de123] Initialize repository 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 demo_file.txt
Now you will need to tell your local git where you will push cli to remotely.
git remote add origin ssh://nugget@gitshed.igazine.com:/home/nugget/repos/repo1/repo1.git git branch -M main
Before you can push to the remote repo you need initialize a bare repo on the git server.
Step 4: Adding the bare repo
On the Git Server you can add the bare repo.
nugget@gitshed:~$ mkdir -p repos/repo1 nugget@gitshed:~$ git init --bare repos/repo1/repo1.git
If you want to verify the .git repo is in the directory you can
nugget@gitshed:~$ ls -la repos/repo1 total 24 drwxr-xr-x 6 nugget nugget 4096 May 27 05:45 . drwxr-xr-x 4 nugget nugget 4096 Mar 18 03:45 .. drwxr-xr-x 7 nugget nugget 4096 May 27 05:54 repo1.git
Step 5: back to the Local Device Now if you have done all of the other steps correctly you should be able to simply push cli from your laptop to the server.
[laptop]$ git push -u origin main Enumerating objects: 3, done. Counting objects: 100% (3/3), done. Writing objects: 100% (3/3), 229 bytes | 229.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 To ssh://gitshed.igazine.com:/home/nugget/repos/repo1/repo1.git * [new branch] main -> main branch 'main' set up to track 'origin/main'.
Step 6: Testing from your other devices Alright you were able to connect things from one of your devices to a git repo you built out in the cloud some place. Now you want to check things with your other devices in this case I will use my home PC this can be done easily with a simple clone of the repo. As long as you have ssh keys and accounts synced up (just like above) this should just work. You may want to copy into a local “repos” directory just to keep things consistent in your dev environments.
nugget@kalin-nugget:~$ mkdir repos nugget@kalin-nugget:~$ cd repos nugget@kalin-nugget:~$ git clone ssh://nugget@gitshed.igazine.com/home/nugget/repos/repo1/repo1.git/ Cloning into 'repo1'... remote: Enumerating objects: 3, done. remote: Counting objects: 100% (3/3), done. Receiving objects: 100% (3/3), done. remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 nugget@kalin-nugget:~$ ls repo1 demo_file.txt
At the end you should be able to list the directory and have the exact same files you have on your other system. You can figure out git workflows and collaboration if you check out the Learn Enough GIT classes like I mentioned above.