threads / discuss / 28268

need to create new repository initially seeded with several branches

Subject: need to create new repository initially seeded with several branches

## tl;dr

11 messages between Aug 31, 2011 and Aug 31, 2011.

replies: 10people: 5as markdown or json

ryan@iridiumsuite.com· Aug 31, 2011, 15:25 UTC · lore

Noobie here...Don't ask why, but I have essentially 3 branches in separate code bases on my file system that aren't in a repository right now.

I would like to turn this into a git repository. One branch being master, the second develop and finally a third branch that is extended off the develop branch.

Is there a way to do this? Could someone give me a step by step? I am having a hard enough time just getting use to git and I am lost trying to figure this out.

thanks so much

-- View this message in context: http://git.661346.n2.nabble.com/need-to-create-new-repository-initially-seeded-with-several-branches-tp6746957p6746957.html Sent from the git mailing list archive at Nabble.com.

in-git-vger@baka.org· Aug 31, 2011, 15:40 UTC · re: ryan@iridiumsuite.com · lore

Re: need to create new repository initially seeded with several branches

In message <1314804325568-6746957.post@n2.nabble.com>, "ryan@iridiumsuite.com" writes:
    I would like to turn this into a git repository.  One branch being master,
    the second develop and finally a third branch that is extended off the
    develop branch.
I will assume in my instructions that develop is "extended" off of master.

---------------------------------------------------------------------- cd /path/to/new/master # Make this a git repo git init # Add all files to git git add . # Commit all files to git git commit -m "initial master version" # Make new develop branch git checkout -b develop # Cause git to delete all files in the internal index git read-tree --reset -i 4b825dc642cb6eb9a060e54bf8d69288fbee4904 # Cause git to delete all files in the working directory git clean -dfx # Copy all files from the develop directory cp -r /path/to/new/develop . # Add all files to git (and delete them too) git add -A . # Commit git commit -m "Initial develop branch" # Make new extended branch git checkout -b extended # Cause git to delete all files in the internal index git read-tree --reset -i 4b825dc642cb6eb9a060e54bf8d69288fbee4904 # Cause git to delete all files in the working directory git clean -dfx # Copy all files from the extended directory cp -r /path/to/new/extended . # Add all files to git (and delete them too) git add -A . # Commit git commit -m "Initial develop branch" ----------------------------------------------------------------------

The only "magic" is the read-tree/git-clean stuff. The 4b82… value is the SHA of an empty tree. It could be replaced by a:

find . -maxdepth 1 ! -name '.git' -a ! -name '..' -a ! -name '.' -print0 | xargs -0 rm -rf
But that is 9 extra characters.
Untested, but it should work.
					-Seth Robertson
Ryan Wexler· Aug 31, 2011, 16:10 UTC · re: in-git-vger@baka.org · lore

Re: need to create new repository initially seeded with several branches

On Wed, Aug 31, 2011 at 8:40 AM,  <in-git-vger@baka.org> wrote:
Show 54 quoted lines
>
> In message <1314804325568-6746957.post@n2.nabble.com>, "ryan@iridiumsuite.com" writes:
>
>    I would like to turn this into a git repository.  One branch being master,
>    the second develop and finally a third branch that is extended off the
>    develop branch.
>
> I will assume in my instructions that develop is "extended" off of master.
>
> ----------------------------------------------------------------------
> cd /path/to/new/master
> # Make this a git repo
> git init
> # Add all files to git
> git add .
> # Commit all files to git
> git commit -m "initial master version"
> # Make new develop branch
> git checkout -b develop
> # Cause git to delete all files in the internal index
> git read-tree --reset -i 4b825dc642cb6eb9a060e54bf8d69288fbee4904
> # Cause git to delete all files in the working directory
> git clean -dfx
> # Copy all files from the develop directory
> cp -r /path/to/new/develop .
> # Add all files to git (and delete them too)
> git add -A .
> # Commit
> git commit -m "Initial develop branch"
> # Make new extended branch
> git checkout -b extended
> # Cause git to delete all files in the internal index
> git read-tree --reset -i 4b825dc642cb6eb9a060e54bf8d69288fbee4904
> # Cause git to delete all files in the working directory
> git clean -dfx
> # Copy all files from the extended directory
> cp -r /path/to/new/extended .
> # Add all files to git (and delete them too)
> git add -A .
> # Commit
> git commit -m "Initial develop branch"
> ----------------------------------------------------------------------
>
> The only "magic" is the read-tree/git-clean stuff.  The 4b82… value is
> the SHA of an empty tree.  It could be replaced by a:
>
> find . -maxdepth 1 ! -name '.git' -a ! -name '..' -a ! -name '.' -print0 | xargs -0 rm -rf
>
> But that is 9 extra characters.
>
> Untested, but it should work.
>
>                                        -Seth Robertson
>

Seth- Thanks for the extensive reply. I am excited that this is even possible.

I have to say that I am lost by the "magic" you describe. I don't understand what you mean by the 4b82... value should be replaced by the find | xargs remove all command. That command looks like it just deletes all the "." file names? But when you say replace I thought you would mean I need to generate a new value to replace that magic number?? Confused...

in-git-vger@baka.org· Aug 31, 2011, 16:21 UTC · re: Ryan Wexler · lore

Re: need to create new repository initially seeded with several branches

In message <CAKjsY4nsPNO_kvxeime8qcNrRFykgG2TOYxJ0HKbj2zR5Rwv+Q@mail.gmail.com>, Ryan Wexler writes:
    > # Cause git to delete all files in the internal index
    > git read-tree --reset -i 4b825dc642cb6eb9a060e54bf8d69288fbee4904
    > # Cause git to delete all files in the working directory
    > git clean -dfx
    > The only "magic" is the read-tree/git-clean stuff.  The 4b82…
    > value is the SHA of an empty tree.  It could be replaced by
    > a:
    >
    > find . -maxdepth 1 ! -name '.git' -a ! -name '..' -a ! -name '.' -print0 | xargs -0 rm -rf
    I have to say that I am lost by the "magic" you describe.  I don't
    understand what you mean by the 4b82... value should be replaced by
    the find | xargs remove all command.   That command looks like it just
    deletes all the "." file names?  But when you say replace I thought
    you would mean I need to generate a new value to replace that magic
    number??  Confused...

I was just trying to explain what the git-read-tree and git-clean commands are doing. The long string starting with 4b825d is a special SHA that git knows represents an empty tree. I was saying that you *could* (not should) replace the two commands (git-read-tree and git-clean) with the "find | xargs rm" command I quoted. The two sets of commands are equivalent.

Also, if you look at the find command, I am finding everything *except* the .git . and .. directories

					-Seth Robertson
Johannes Sixt· Aug 31, 2011, 17:48 UTC · re: in-git-vger@baka.org · lore

Re: need to create new repository initially seeded with several branches

Am 31.08.2011 17:40, schrieb in-git-vger@baka.org:
Show 7 quoted lines
> # Cause git to delete all files in the internal index
> git read-tree --reset -i 4b825dc642cb6eb9a060e54bf8d69288fbee4904
> # Cause git to delete all files in the working directory
> git clean -dfx
> ...
> The only "magic" is the read-tree/git-clean stuff.  The 4b82… value is
> the SHA of an empty tree.  It could be replaced by...
... a simple
  git rm -rf .
-- Hannes
Brandon Casey· Aug 31, 2011, 16:14 UTC · re: ryan@iridiumsuite.com · lore

Re: need to create new repository initially seeded with several branches

On 08/31/2011 10:25 AM, ryan@iridiumsuite.com wrote:
Show 10 quoted lines
> Noobie here...Don't ask why, but I have essentially 3 branches in separate
> code bases on my file system that aren't in a repository right now.  
> 
> I would like to turn this into a git repository.  One branch being master,
> the second develop and finally a third branch that is extended off the
> develop branch.
> 
> Is there a way to do this?  Could someone give me a step by step?  I am
> having a hard enough time just getting use to git and I am lost trying to
> figure this out.
So, you want your repository and dag to look like this:
     *------*------*
     |      |      |
  master  devel  topic
but it may help you visualize it to write it like this:
  master *
          \
     devel *
            \
       topic *

Just be aware that the above two are the same. If you don't understand that now, then let this plant the seed in your brain of the concept that branches are merely "pointers" to a state of your repository. Don't worry, you don't have to understand that now in order to get started and accomplish what you are trying to do...

First, create your git repository based on the code in the directory holding what you would like to become the master branch.

Either
   cd $path_to_master_code
or
   mkdir $my_new_project_directory &&
   cd $my_new_project_directory &&
   cp -a $path_to_master_code/* .
then
   git init &&
   git add . &&
   git commit -m 'Initial import into git'

Voila, you have your master branch. Now just create your devel branch and copy your devel code into it and commit.

   git checkout -b devel &&  # make a new branch named "devel"
                             # which has the same state as the
                             # currently checked out branch: "master"
                             # i.e. devel and master point to the
                             # same tip commit.
   rm -rf * &&               # remove the files in the working dir
   cp -a $devel_dir/* . &&   # cp devel source code to working dir
   git add -A . &&           # add new/removed files to the index
                             # to be committed on next 'git commit'
   git commit
   # use editor to give descriptive commit message
Repeat for your topic branch based off of devel.

Please make sure you read the man pages for the above commands and understand what is going on before you do it, and double-check my commands.

-Brandon
Jeff King· Aug 31, 2011, 16:54 UTC · re: Brandon Casey · lore

Re: need to create new repository initially seeded with several branches

On Wed, Aug 31, 2011 at 11:14:48AM -0500, Brandon Casey wrote:
Show 13 quoted lines
>    git checkout -b devel &&  # make a new branch named "devel"
>                              # which has the same state as the
>                              # currently checked out branch: "master"
>                              # i.e. devel and master point to the
>                              # same tip commit.
>    rm -rf * &&               # remove the files in the working dir
>    cp -a $devel_dir/* . &&   # cp devel source code to working dir
>    git add -A . &&           # add new/removed files to the index
>                              # to be committed on next 'git commit'
>    git commit
>    # use editor to give descriptive commit message
> 
> Repeat for your topic branch based off of devel.

I am probably just going to confuse the original poster more, but here is how I would do it. It's slightly more efficient, as it doesn't involve removing and copying files for the intermediate states:

  # make a repo and switch to it
  git init repo && cd repo
  # and now add everything from the "master" version, and
  # make a commit out of it
  GIT_WORK_TREE=/path/to/master git add -A
  git commit
  # now make the devel branch and do the same
  git checkout -b devel
  GIT_WORK_TREE=/path/to/devel git add -A
  git commit
  # and then check out the result in the working tree of
  # your newly created repo
  git checkout -f
-Peff
Brandon Casey· Aug 31, 2011, 17:01 UTC · re: Jeff King · lore

Re: need to create new repository initially seeded with several branches

On 08/31/2011 11:54 AM, Jeff King wrote:
Show 36 quoted lines
> On Wed, Aug 31, 2011 at 11:14:48AM -0500, Brandon Casey wrote:
> 
>>    git checkout -b devel &&  # make a new branch named "devel"
>>                              # which has the same state as the
>>                              # currently checked out branch: "master"
>>                              # i.e. devel and master point to the
>>                              # same tip commit.
>>    rm -rf * &&               # remove the files in the working dir
>>    cp -a $devel_dir/* . &&   # cp devel source code to working dir
>>    git add -A . &&           # add new/removed files to the index
>>                              # to be committed on next 'git commit'
>>    git commit
>>    # use editor to give descriptive commit message
>>
>> Repeat for your topic branch based off of devel.
> 
> I am probably just going to confuse the original poster more, but here
> is how I would do it. It's slightly more efficient, as it doesn't
> involve removing and copying files for the intermediate states:
> 
>   # make a repo and switch to it
>   git init repo && cd repo
> 
>   # and now add everything from the "master" version, and
>   # make a commit out of it
>   GIT_WORK_TREE=/path/to/master git add -A
>   git commit
> 
>   # now make the devel branch and do the same
>   git checkout -b devel
>   GIT_WORK_TREE=/path/to/devel git add -A
>   git commit
> 
>   # and then check out the result in the working tree of
>   # your newly created repo
>   git checkout -f
Better.
-Brandon
Ryan Wexler· Aug 31, 2011, 17:09 UTC · re: Brandon Casey · lore

Re: need to create new repository initially seeded with several branches

Ok thanks for all the replies guys. I thought I was SOL. I will start playing with it here and let you know how it goes.

On Wed, Aug 31, 2011 at 10:01 AM, Brandon Casey <brandon.casey.ctr@nrlssc.navy.mil> wrote:

Show 42 quoted lines
> On 08/31/2011 11:54 AM, Jeff King wrote:
>> On Wed, Aug 31, 2011 at 11:14:48AM -0500, Brandon Casey wrote:
>>
>>>    git checkout -b devel &&  # make a new branch named "devel"
>>>                              # which has the same state as the
>>>                              # currently checked out branch: "master"
>>>                              # i.e. devel and master point to the
>>>                              # same tip commit.
>>>    rm -rf * &&               # remove the files in the working dir
>>>    cp -a $devel_dir/* . &&   # cp devel source code to working dir
>>>    git add -A . &&           # add new/removed files to the index
>>>                              # to be committed on next 'git commit'
>>>    git commit
>>>    # use editor to give descriptive commit message
>>>
>>> Repeat for your topic branch based off of devel.
>>
>> I am probably just going to confuse the original poster more, but here
>> is how I would do it. It's slightly more efficient, as it doesn't
>> involve removing and copying files for the intermediate states:
>>
>>   # make a repo and switch to it
>>   git init repo && cd repo
>>
>>   # and now add everything from the "master" version, and
>>   # make a commit out of it
>>   GIT_WORK_TREE=/path/to/master git add -A
>>   git commit
>>
>>   # now make the devel branch and do the same
>>   git checkout -b devel
>>   GIT_WORK_TREE=/path/to/devel git add -A
>>   git commit
>>
>>   # and then check out the result in the working tree of
>>   # your newly created repo
>>   git checkout -f
>
> Better.
>
> -Brandon
>
Brandon Casey· Aug 31, 2011, 16:45 UTC · lore

Re: Re: need to create new repository initially seeded with several branches

On 08/31/2011 11:24 AM, in-git-vger@baka.org wrote:
Show 11 quoted lines
> 
> In message <sDZ5pnWzh3ZbFYS6GK-NcPdn09kF53MJ2eRkBnzInzdL8-cvCiF5beUw2k9Pz6BTq-Y3i_XwpYfgTOvXNlP1vPjLSHJ6FIzxL0jN1W0d0M8@cipher.nrlssc.navy.mil>, Brandon Casey writes:
> 
>        rm -rf * &&               # remove the files in the working dir
> 
> I just note (for your information only) that this doesn't get rid of
> any . files which might exist.  That is the advantage of the
> git-read-tree;git-clean or the `find | xargs rm` alternatives I
> mentioned in my post.  99% of the time it doesn't matter of course,
> since it would only fail on . files which were deleted in the data
> stream you were replacing.
I was just crafting a reply to your message to say the same thing.

Note also that the dot files would not have been copied into the working directory in the first place, using a command like this:

   cp -a /some/path/* .

So, Ryan, if your project contains dot files that you would want to track, take care that they are actually copied and deleted with the other files while you are creating your repository.

-Brandon
Brandon Casey· Aug 31, 2011, 16:54 UTC · re: Brandon Casey · lore

Re: Re: need to create new repository initially seeded with several branches

@Seth Robertson
Your email address seems to be broken.  My message to you bounced:
   ----- The following addresses had permanent fatal errors -----
<in-git-vger@baka.org>
    (reason: 550 5.1.1 <in-git-vger@baka.org>... User unknown)
   ----- Transcript of session follows -----
... while talking to tsutomu.baka.org.:
>>> >>> DATA

<<< 550 5.1.1 <in-git-vger@baka.org>... User unknown 550 5.1.1 <in-git-vger@baka.org>... User unknown <<< 503 5.0.0 Need RCPT (recipient)

   ----- Original message follows -----
<snip>

← back to recent threads