There seem to be lots of multi-step, ssh to the server style instructions how to create a new remote repository, and then push to it, but they’re all much more complex than git init.
I have many many local repositories that I decided to backup on my server, and then I can push&pull from them from my other computers too.
so – to the 1.5 steps:
0.5 create a new script called ‘create_backup.sh’ (customizing the $ssh_setting value for your ssh-able server)
#!/bin/sh ssh_setting='user@your_server.net:~/git' if [ -z $1 ]; then echo "usage: ./create_backup.sh RepoDir" else scp -r $1/.git $ssh_setting/$1 cd $1 git config --add alias.backup "push --mirror $ssh_setting/$1" ssh email@example.com "cd git/$1 && git config --bool core.bare true" git config remote.backup.url $ssh_setting/$1/ git backup cd .. fi
1. You can then run ./create_backup.sh YourLiveRepo which will create a full (but bare) copy of your repository, and add an alias that will allow you to run git backup to mirror all changes on all local branches to the backup.
The script also creates a remote.backup link that you can push and pull from in case you’re then going to clone that repo like a ‘normal’ ssh based remote.
On one local computer I can thus create a new shareable repository by running
and then my new coworker can then clone it and start pushing updates:
git clone user@yourserver:~/git/NodeJsProject1