How to use tsrc to manage multiple git repositories and remotes

Albert De La Fuente Vigliotti
Related notes
How to list all projects in Gitlab, How to list all projects in Github

Install the package #

pip install --user tsrc

Create the manifest repository #

  • Create a new repository named manifest
  • Create a file manifest.yml with the following content:
repos:
  - dest: org
    branch: master
    remotes:
    - name: origin
      url: git@github.com:<user>/<repo>.git
    - name: https
      url: https://<user>:<token>@github.com/<organization>/<repo>.git
    - name: nas
      url: ssh://<user>@<server>:<port>/<path>/<repo>.git

This will create the setup for a repository that always stays in sync across all the remotes. The cool thing about this is that it will automatically keep in sync the git remotes with this definition. I have been looking out for this for a long time, this is really cool.

Init the repository and sync #

cd ~
tsrc init git@github.com:<user>/manifest.git
tsrc --verbose sync

Sync via https #

tsrc --verbose sync -r https

Migrating from master to main branch #

  • Make sure the master branch is clean and there is nothing to commit nor staged
  • Change to the main branch with git checkout --track origin/main
  • Remove the readme if needed rm README.md
  • Merge with git merge --allow-unrelated-histories master
  • Add the changes git add .
  • Commit git commit -m 'Merge with master branch'
  • Push git push
  • Delete the master branch locally git branch -d master
  • Delete the master branch remotely git push origin --delete master
  • Change branch: master to branch: main in the manifest.yml file
  • Commit and push the manifest.yml file

Sometimes it is needed to git branch --set-upstream-to=origin/master master

Sync a group #

This command works and will sync the org-media content (it will create the repo if it doesn’t exists). However I am not sure I understand why the -r org flag is needed. The status command instead of sync is useful for debugging.

tsrc --verbose sync -r nas --group org-group -r org

Resources #

tsrc documentation #