Promoting a git project to a bare repo
I usually develop on local disk, just git init and start programming. No push or pull, no remote repos. But sometimes I want to get fancy and have a remote repo. I don’t use GitHub or GitLab to host these projects, I just host them myself. But things have changed a bit in the intervening 12 years, here’s the new process.
### Clone existing code into a new bare repo cd ~/gitrepos git clone --bare ~/src/blog/static/flourish/ flourish ### Set up origin in the old existing code cd ~/src/blog/static/flourish git remote add origin example.com:~/gitrepos/flourish git push --set-upstream origin main ### Verify things are working as expected git remote -v git branch -avv
One subtle thing there... The bare repo is created by cloning from local disk. But then I set the origin back in my working code via an SSH URL. Not strictly necessary in the case where both the bare repo and the working copy are on the same computer but the whole point here is to enable working copies on multiple machines from the same bare repo.
And an extra complication: I have Syncthing synchronizing my ~/src to my various Linux development environments. All behind the scenes, transparently. This can be a little spooky sometimes; if I git commit in one working copy there’s no need to git pull in another working copy because syncthing will sync for me. It’s harmless to git pull and git push in this configuration though, at least as long as I’m not making changes in two places at once.