AlanObject
AlanObject

Reputation: 9963

Preserving branches in private git repository

We have a git repository that collects all our company's private branches off of a public repository that comes from a project on GitHub. We implement features that we don't want to push upstream, and those branches are typically based off of some tagged release from the public repository.

So far so good. When I want to pull later revisions from the public repository, I use the

git fetch

command and then we can use those later versions to rebase our code on or implement other new branches. However, if someone accidentally types the command:

git -p fetch

then our repository is purged of all branches that don't appear in the remote/origin. Of course, none of are private stuff is up there so we could lose all or a chunk of our work that doesn't happen to be saved in one of our repository clones or a file system backup.

This seems like a very fragile situation that I would like to protect against. Are we using the git facility in a way that it shouldn't be or is there some better way of doing this?

Upvotes: 1

Views: 50

Answers (2)

max630
max630

Reputation: 9238

git is not meant to be a backup replacement. However you are accurate with fetch it won't save you from storage failure.

Anyway, you can do 2 things:

  • backup .git/refs, .git/logs directories and .git/packed-refs file. Reflogs unfortunately are deleted as you delete the branch, so you cannot rely on them.
  • there is "precious objects" extension, enable it as described there. Then objects are never collected and if you restore branches from backup you can be sure they are valid.

Upvotes: 1

andy magoon
andy magoon

Reputation: 2929

By using the git fetch -p flag you're telling git to prune. I don't know what to say, you're actually directing it to do something destructive. Of course, with git, you can always use git reflog to walk back. Just check out the branch using the hash.

Upvotes: 1

Related Questions