Have you ever had your version control server go down just when you were ready to commit some important changes for your team? Did you feel stuck, blocked, or hopeless? This happened to me only yesterday but luckily we use Git for version control. Git is a decentralized version control system which means that you don’t actually need a central host to continue working. While lots of people already know that you can commit, merge, and branch locally without a network connection you may be surprised to know that you can also push and pull changes while the central Github repository is offline using a Peer 2 Peer connection.
Last night I wanted to push changes from my iMac in the office so I could pull them with my Macbook and work from home. Our internal Github repository went offline and I went to Google to find a little trick I’d used in the past. Setting an alias to run a local git server is as simple as:
git config --global alias.serve "daemon --verbose --export-all --base-path=.git --reuseaddr --strict-paths .git/"
This creates a git command, serve, that you can run from the command line to launch a local Git server over your current repository.
I ran this command on my iMac and got output saying something like, “Ready to rumble“. My local git server was ready to accept connections from other computers. On my Macbook I was then able to pull the commits I had just made on the iMac using it’s IP address with the git pull command:
git pull git://10.15.12.15/ feature/newWidget
The “feature/newWidget” was the name of the branch I was pulling. Some output text on the Mac confirmed a remote connection happened and the new commits magically showed up on my Macbook Pro. This same idea could apply if I needed to share my latest branch with a coworker before heading home. I could commit to a feature branch on my iMac and then say, “pull the changes from my iMac at 10.15.12.15”. My coworker could run a similar git pull and see all of the commits appear in their local repository. The alias I used above is read only, however you could also set it up so that coworkers have write access and can push directly to your local git repo as they complete work.
So the next time your internal version control host goes offline don’t sweat it! Run a local git server and share away! I haven’t tried it but I believe this might work with a git-svn setup as well.