benefits of this over `git clone --bare` and `git push --mirror`?
Closed this issue ยท 2 comments
Hello! ๐
I'm interested in hosting some internal Git mirrors on GitHub for some SourceForge Git repositories. I was hunting around on the GitHub Actions marketplace and found this GitHub Action. I also Googled some and found that the "recommended" way to mirror a Git repository by GitHub is this:
git clone --bare https://git.code.sf.net/p/mingw/regex .
git push --mirror https://github.com/octocat/mingw-regex.git
where https://github.com/octocat/mingw-regex.git
can have a https://username:password@github.com/...
auth URL part where username
is anything (even just x
) and password
is a GitHub Personal Access Token. https://stackoverflow.com/questions/18935539/authenticate-with-github-using-a-token
Is there an advantage to using this GitHub Action over something like this? Am I missing something?
# octocat/.github or another third repository
# .github/workflows/mirror-mingw-regex-to-octocat-mingw-regex.yml
name: Mirror mingw/regex to octocat/mingw-regex
on:
schedule:
- cron: "36 */6 * * *"
workflow_dispatch:
jobs:
mirror-mingw-regex-to-octocat-mingw-regex:
runs-on: ubuntu-latest
steps:
- run: git clone --bare https://git.code.sf.net/p/mingw/regex .
- run: git push --mirror "https://x:$TOKEN@github.com/octocat/mingw-regex.git"
env:
TOKEN: ${{ secrets.MINGW_REGEX_TOKEN }}
If I recall correctly, the reason why this strategy is not used in this Action is because git clone --bare ...
and git push --mirror
is that --mirror
will cause everything to be mirrored (as opposed to this action allowing branches to be selectively mirrored) and will delete branches on the remote not present on the source, which can be a destructive and undesirable behavior, especially if the goal is preservation.
In short, the behavior of --mirror
is usually not what users actually want to do.
If you do wish to have this behavior, it is possible to configure this in the GIT_PUSH_ARGS
option for this action to use --mirror
. Since the clone/checkout process is not part of this action (you should use actions/checkout
for example), you can also configure --bare
in the action steps you use to clone your repository as well.
Couple of references you might find helpful:
- https://stackoverflow.com/a/3341392/5747944
- https://github.blog/changelog/2022-06-15-block-potentially-destructive-git-pushes/
Hope that helps answer your question.
Thanks for the detailed comparison! I'm using a tool that requires a user/repo
slug to resolve against GitHub and doesn't accept non-GitHub Git repos ๐ค so I think the basic git push --mirror
is perfect for me. Thanks again for the explanation! ๐