How to back up private branches in git

I have a local branch for day-to-day dev work in git. My workflow is:

  • Do stuff on local_branch, commit
  • Fetch origin/master
  • Rebase local_branch to catch up with new stuff from origin/master
  • It all works fine, however most of the recommendations I encountered say that one should not "push" private branches, on which rebase is regularly performed.

    The problem here is that in this case local branch is not backed up to a server and the only way to save the work is to merge it back to "pushable" branch (ie origin/master)

    What would be your recommendations on the workflow in this case?

    Thanks!

    UPDATE : I realised that one of the original requirements I had (avoiding usage of external utilities) is unnecessary limiting.

    My current solution is to store all my repositories in a cloud-synchronised folder - this way I get backup for free.


    I use the --mirror option and push to a personal backup repository:

    Add it as a remote:

    git remote add bak server:/path/to/backup/repo
    

    Do the backup:

    git push --mirror bak
    

    This will automatically make your backup repository look like your active one -- branches will be created, deleted, updated (even forced/non-fastforwards) as needed. You can make an alias for this too:

    git config alias.bak "push --mirror bak"
    

    Then, it's just a matter of running "git bak" when you want to do a backup. You could also throw this into a cron job.


    Another option would be to push "local_branch" to the "origin" repo, but to it's own branch in that repo (not "master"), ie:

    git push origin local_branch:local_backup

    Then when you are ready to make another backup (and after you've been doing some work and rebasing) just delete the backup branch from the origin repo before you push it out again:

    git push origin :local_backup <=== deletes the branch from origin

    git push origin local_branch:local_backup

    This way you won't run into problems pushing "local_branch" after it has been rebased from "origin/master".

    And if deleting your backup branches makes you nervous (until after you've finally committed your work to "master"), you could always keep pushing to a new branch with a new name (eg "local_backup1", "local_backup2", etc).


    There's nothing wrong with pushing personal branches. It is generally discouraged because people might start work based on your branch, and when you rebase, their changes are left floating.

    What I do is use a prefix to denote "this is my branch, use it on your own risk", like: fc-general-cleanup .

    链接地址: http://www.djcxy.com/p/48930.html

    上一篇: Git在修改提交后阻止推送

    下一篇: 如何备份git中的私人分支