2

I worked locally on a git repository. It has various branches like a dev branch, some branch for experimental changes and so on. And of course a master branch.

I want to setup a public (well, indeed it's a lan thing, better say "shared") repository to only contain the master branch.

How to export that branch so that i can copy it to the destination folder? Thanks

pistacchio
  • 56,889
  • 107
  • 278
  • 420

2 Answers2

2

As the git-push manual says:

git push origin HEAD:master

Push the current branch to the remote ref matching master in the origin repository. This form is convenient to push the current branch without thinking about its local name.

or

git push origin HEAD

A handy way to push the current branch to the same name on the remote.

Using these commands you do:

  1. Create git init --bare repository at some "shared location"
  2. git remote add origin this location to your current working repository
  3. git push --force origin HEAD from your master branch
  4. Other devs now can clone that repository with only master branch
Marcin Gil
  • 68,043
  • 8
  • 59
  • 60
  • Oh, is OP talking about remote public repository? – Michael Krelin - hacker Mar 03 '10 at 10:52
  • He exactly says he want's to create new repo. Doesn't matter if that's really remote or just another directory. Added some info to clarify. Thanks. – Marcin Gil Mar 03 '10 at 11:15
  • Well, it does. If it's locally, I wouldn't like the solution you propose. – Michael Krelin - hacker Mar 03 '10 at 13:00
  • Care to explain why? It works for me. As it is a "lan thing" then it can be that this directory will be shared over CFS/Samba or served via ssh. – Marcin Gil Mar 03 '10 at 13:21
  • Sure it works. The drawbacks are (a) you have to push each time you commit (with alternates and symlink trick that should do automatically) and (b) it takes twice as much space, although in case of local machine could be fixed in your solution (it will turn it into a repetition of the first part of my proposal;-)). And yes, the "lan thing" of course leaves quite some room for imagination. – Michael Krelin - hacker Mar 04 '10 at 11:44
  • 1
    Well.. In my work I only push to shared repo once a feature/bugfix/etc is ready and not every single commit that can be partial solution. As for the space requirement, well.. disks are cheap now and you gain repo separation: your own workplace and what you share with others. Moreover symlinking to your own workplace as shared place will share what you have actually checked out won't it? – Marcin Gil Mar 04 '10 at 12:06
  • 1
    It most certainly will share whatever you have checked out. AFAIK, there is no symlink solution that will work for the OP's problem. I, for one, really like the solution you've proposed @MarcinGil and furthermore it represents an interesting solution for my current problem, similar to this: http://stackoverflow.com/questions/8271263/repair-corrupted-git-repository – steve Jan 02 '12 at 22:25
0

I'd consider setting up separate public repository with "alternates" pointing to the one you're working on and push your branch to it. Or maybe symlink the master branch to the one in your local repository. I haven't tried that, but it should work.

Michael Krelin - hacker
  • 138,757
  • 24
  • 193
  • 173
  • I don't believe you can symlink to a specific branch, only to a specific dir (which would have whatever you've checked out in it). That said, an alternate remote with only "master" branch is a perfectly good solution too. – steve Jan 02 '12 at 22:22
  • @steve, by branch I meant a working directory. I think so, at least. It's been a while since I wrote it :) Sure you can't symlink branch as in revision. – Michael Krelin - hacker Jan 03 '12 at 10:17