8

My question might seem a bit strange since what I want can usually be accomplished by simply deleting the repository and creating a new one. Here's the reason why I still need to keep the repository: The history of my repository is actually the most valuable part of the repository. I generate an entire repository with all the data. The repository is hosted on github and I want to update the repository there to look exactly like the local repository (identical history).

The only way I have found to do this so far has been to delete and recreate the repository on github before pushing to it. Otherwise all of the old commits would still be there, effectively altering the historical information of the repository. Of course it is fairly easy to recrate a repository on github but along with the repository all watchers, wiki info etc. are lost and I'd like to prevent that.

I've posted here instead of github since I think that this question is rather related to Git than to the hosting service.

Any thoughts?

2 Answers 2

5

A forced push such as git push origin +master should help. All remote changes will be lost.

7
  • Sounds interesting. I'll have to give that I try. What would happen though if the old repository had a branch master but in the new repository the branch was named differently. Wouldn't the master branch just stay alive?
    – Max Leske
    Commented Mar 16, 2011 at 10:59
  • @theseion: I'd question why you weren't using a branch named master - it's a pretty strong convention - but you can certainly push all the branches you care about (with -f if necessary), and delete all the branches you don't want, e.g. git push origin :oldbranch.
    – Cascabel
    Commented Mar 16, 2011 at 13:36
  • @Jefromi: I agree, normally I wouldn't change master. But in this repository the branches have a special meaning. Deleting a branch is not exactly what I want since that only removes the reference to the commit marked by that branch but not all the commits of that branch (of course that is also not exactly what I want but close enough).
    – Max Leske
    Commented Mar 16, 2011 at 16:00
  • @Alan: please correct me if I'm wrong but your suggestion does more or less the same as Jonathan's: the reference is changed but all the objects stay intact. I'll try to clarify my question.
    – Max Leske
    Commented Mar 16, 2011 at 16:11
  • @Alan: Actually rerouting the references is enough to achieve what I want. Your were right there. Since my repository is pretty big, how would I then get rid of the unreachable objects? Doing a git gclocally doesn't affect the remote pack file as far as I understand...?
    – Max Leske
    Commented Mar 16, 2011 at 16:28
2

Step 1: Delete all remote branches:

git fetch
git branch -r

For each line of output (they should look like origin/master, origin/branch1, ...) add it to a git push line like this:

git push origin :master :branch1 ...

Step 2: Push your local branches

git push origin master branch1 ...
7
  • @Jonathan: As commented below, only deleting / rerouting the references to the commits marked by the branches does not solve the problem.
    – Max Leske
    Commented Mar 16, 2011 at 16:02
  • 1
    @theseion How so? How does this not make the remote repository look just like your local? Old history becomes inaccessible, and your local history is pushed to the remote...
    – Jonathan
    Commented Mar 16, 2011 at 16:38
  • @Jonathan: yes you are of course right (see Alan's answer), that's why I upvoted your answer.
    – Max Leske
    Commented Mar 16, 2011 at 16:59
  • @theseion Thank you, I was worried that I had not only missed something, but not understood Alan's answer.
    – Jonathan
    Commented Mar 16, 2011 at 17:02
  • 1
    @MatrixFrog It would only be accessible if you were actually on GitHub. There is no way using git fetch to retrieve orphaned objects from a remote. Although I suppose SSH access may grant you enough access to manually acquire them.
    – Jonathan
    Commented Mar 17, 2011 at 13:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.