Skip to content

back up master branch only #109

Description

@zzc-tongji

I use the following command to back up all my repo.

github-backup --token TOKEN --output-directory DIRECTORY --repositories --private --fork USER

It seems that github-backup only backs up master branch. All other branches are ignored.

Activity

  1. zzc-tongji commented on May 10, 2019

    @zzc-tongji
    Author

    Is there any way to back up ALL things of the git repo? Just like "copy" from GitHub.

  2. josegonzalez commented on May 10, 2019

    @josegonzalez
    Owner

    It clones the whole repo, so all commits are there, you just need to checkout the branch you want.

  3. riophae commented on Aug 2, 2019

    @riophae

    Hi, how about using this trick to clone with all the branches?
    https://gist.github.com/fernandoaleman/853916e1903b475820f5416bfe048cb8
    In this way, the final result seems less confusing to me.

  4. einsteinx2 commented on Jan 7, 2020

    @einsteinx2
    Contributor

    So as @josegonzalez mentioned, all of the branches are in fact backed up and completely accessible if the remote repo goes away or if you don't have internet access.

    You can easily view them using git branch -a and then check out and track any remote branch you want using git checkout --track origin/branch_name. Again, this works even if the remote gets deleted or if you have no internet access, as all of the remote branches are actually there locally, they're just not tracked.

    @riophae the problem with that trick, is that while it works the first time, if you try to update the repo later using git fetch to continue backing up new changes, it will fail because it's no longer a bare repo.

    For example (the extra flags are not causing the problem, a simple git fetch will fail with the same error, I'm just using the exact command here that the script does to update backups)

    linux-mint-vm :: ~/Desktop/branch-test ‹git master› » git fetch --all --force --tags --prune
    Fetching origin
    fatal: Refusing to fetch into current branch refs/heads/master of non-bare repository
    error: Could not fetch origin
    

    So while it seems nice in theory, it seems like would only work for a one time backup...

    However, I just tried setting core.bare to true again after the first clone before fetching using git config --local --bool core.bare true. That allowed the fetch to work and then when I pushed a new branch on another machine and used the same git fetch --all --force --tags --prune command again, not only did it sync the new branch but it tracked it and everything. So there may actually be a way to make this work!

    Interestingly, when I tested doing a normal clone first then doing the rest of the steps in that link and setting core.bare to true again, it didn't track any of the new branches. It seems to only work if you first perform steps as described in that link, which is strange...

    This seems very hacky though and potentially prone to breaking in the future as it's not clear if this is intended behavior or just unintentional behavior by the git client, so not sure it's worth implementing at the risk of breaking future backups, especially since as mentioned all of the branch data is in fact being backed up already.

    I'll look into this some more later and do some more testing to better understand why that trick works in the first place. If I can determine that it's safe to implement, I'll try and change the script logic to do that so that all branches are automatically tracked.

  5. Iamrodos commented on Dec 3, 2025

    @Iamrodos
    Contributor

    @josegonzalez this can be closed as it was addressed by #457

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions