Mirror git repositories in simple steps
I have two code repositories. I have a public repository at Github. I have another repository hosted on my server. I use Gogs for my private repository. (If you are interested in Gogs, check out my guide on installing Gogs on webfaction).
With this dual setup, I have all my code (private and public) in one place; as well as, I can choose to share pieces of code with others via Github.
Even if you have all your code out in public, you should still have two repositories so that one can serve as a backup.
The steps for git mirroring are:
Create the repository (in gogs & in github)
Nothing big deal here. Just create a repository in both places. In all the below discussions, gogs is the primary repository and github is the secondary repository.
Clone the gogs repository to your local machine
git clone https://repos.jjude.com/jjude/swift-ios-apps.git
Add github repository as a remote
Go into your local repository directory and add the github repository.
cd swift-ios-apps/ git remote add github https://github.com/jjude/swift-ios-apps.git
If you issue
git remote -v locally, it will list the remote repositories. You can push to this repository by issuing
git push --mirror github. I wanted all my git pushes to be immediately pushed to both repositories. So I edited git config.
Edit git config
Edit .git/config in the local directory (swift-ios-apps in this case). Add a
remote all section similar to the below lines:
[remote "all"] url = https://repos.jjude.com/jjude/swift-ios-apps.git url = https://github.com/jjude/swift-ios-apps.git
Push to both repository
You can issue
git push all to push to both repository.