Git can act as a shared code repository in a large variety of contexts. There is no need to have the code hosted on any of the big providers to just "share" the code and its history in a structured way. If you have anywhere where you can create and share files and folders, you can share your Git repo pretty easily.
An example came up recently when transferring a large amount of code over USB. You could just zip up the source itself and copy these files over the others in the repo, but you may be losing valuable commit history and also run the risk of introducing bugs by missing merge conflicts. Instead, what we can do is set up a Git repo on the USB stick to be our remote.
First we have to create a "bare" git repo on the usb stick itself, before pushing our changes to it (I'm using the rust repo as an example).
/media/rupert/919D-746B $ git init --bare rust /media/rupert/919D-746B $ cd ~/code/rust ~/code/rust $ git remote add usb /media/rupert/919D-746B/rust/ ~/code/rust $ git checkout -b "git-repo-illustration" Switched to a new branch 'git-repo-illustration' ~/code/rust $ git commit --allow-empty -m "An empty commit that I want to transfer" [git-repo-illustration b9ef7815991] An empty commit that I want to transfer ~/code/rust $ git push usb git-repo-illustration Enumerating objects: 1, done. Counting objects: 100% (1/1), done. Writing objects: 100% (1/1), 226 bytes | 226.00 KiB/s, done. Total 1 (delta 0), reused 0 (delta 0), pack-reused 0 To /media/rupert/919D-746B/rust/ * [new branch] git-repo-illustration -> git-repo-illustration
We then take our USB stick containing our repo and amazing new code to another machine, add the USB repo as a new remote, then pull the code:
~/code/rust $ git remote add usb /media/rupert/919D-746B/rust/ ~/code/rust $ git fetch usb remote: Enumerating objects: 1, done. remote: Counting objects: 100% (1/1), done. remote: Total 1 (delta 0), reused 0 (delta 0), pack-reused 0 Unpacking objects: 100% (1/1), 206 bytes | 206.00 KiB/s, done. From /media/rupert/919D-746B/rust * [new branch] git-repo-illustration -> usb/git-repo-illustration * [new branch] master -> usb/master ~/code/rust $ git checkout -t usb/git-repo-illustration Branch 'git-repo-illustration' set up to track remote branch 'git-repo-illustration' from 'usb'. Switched to a new branch 'git-repo-illustration' ~/code/rust $ git --no-pager show commit b9ef781599134937a77eb3715249cd25cbe47c51 (HEAD -> git-repo-illustration, usb/git-repo-illustration) Author: Rupert Rutledge <1982481+Eosis@users.noreply.github.com> Date: Sat Mar 6 11:19:09 2021 +0000 An empty commit that I want to transfer
The USB will behave like a "normal" git remote, and identify any conflicts that have been made so you can complain to those that caused them 😉 .