tags:

views:

70

answers:

3

I started a local git repository. Now, at this point, I want to publish it, say to github, but I don't want to publish the whole history of the project, just the latest revision.

In particular, I'd like to create a local "pub" branch, make some modification on it (possibly hiding sensitive information), and the publishing the "pub" branch.

If I were to do what I said using a plain push, I'll find myself having all the "pub" history published to the remote repository, something I don't want since sensitive information would be published too.

How can this be achieved?

Thanks!

+2  A: 

Take a look at this question.

You could also just swap out the .git folder in your source tree with a different one, and check your code into that when you want to publish.

You can not, however, set up a branch in the same Git repository without sharing the history, because of the way Git works. A repository has a root commit of the initial state, and all other commits are simply deltas against that commit.

But while we are at it, if you don't want to expose version control history, why not simply publish the code as a tarball with a version number, no reason to drag Git into it :)

mikl
+1 for the alternative solution
Andrew Coleson
I would say plush one for the alternate too except he seems to want to publish to github or the like which would make a tarball less useful.
Jeremy Wall
Thank you for your answer. I'd like to publish my code through a git repository mainly for two reasons:1 - I want to track the history of published code.2 - It's nice to have other people collaborate on it.Thank you again.
Cristiano Paris
+2  A: 

A branch must have all its history exported to be pushed.

The solution, in my mind, is to create a new git repository with your latest checkout in it. Then, add that repository as a remote of your current repository. Do your own side work syncing production to dev, and using git patch apply or git rebase -i to move things to production.

That will keep your private development history that you don't want exposed from every showing up.

Autocracy
A: 

I think I'm trying to bend git to do things it's not supposed to handle :)

The simplest solution I came up with is:

1 - Create a "public-draft" branch of master. 2 - Do every modification on it in order to make your code publishable, i.e. hiding passwords and things like that. Subsequent merges will handle these modifications nicely. 3 - When ready, rsync the public-draft with the master of another git repository tracking the remote repository. 4 - Commit all changes and push them to the remote repository.

I'm wondering if the other repository could be replaced by a branch named "public" which never gets merges from other branches but is only merged back to the "public-draft" branches. This allows to merge back changes introduced by other people on the public repository.

Thank you all.

Cristiano Paris
With regards to patching public and merging it back to other branches, yes, you can do exactly that. It's in my answer from yesterday.
Autocracy