Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to back up private branches in git

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

  1. Do stuff on local_branch, commit
  2. Fetch origin/master
  3. 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 (i.e. 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.

like image 411
Art Avatar asked May 29 '09 01:05

Art


People also ask

Can we archive git branches?

Well, there is no such option like archiving branches in git. But we can create a tag with a prefix like “archive”. In other words, we move entry about the feature from branch list to tags list. To restore the branch, checkout it by the tag.

How do I backup a folder in git?

You can backup every file in your git repository by doing the normal git clone <git-url. git> command. By doing that, you download every file in your repository with their actual size and you can do git workflow in it. It's basically the usual way to clone a git repository.


2 Answers

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.

like image 92
Pat Notz Avatar answered Oct 07 '22 01:10

Pat Notz


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.

like image 24
FelipeC Avatar answered Oct 07 '22 01:10

FelipeC