# need to create new repository initially seeded with several branches

11 messages from 2011-08-31 to 2011-08-31. Participants: ryan@iridiumsuite.com, Ryan Wexler, Brandon Casey, in-git-vger@baka.org, Jeff King, Johannes Sixt.
Thread: https://gitlist.dev/t/28268

## ryan@iridiumsuite.com, 2011-08-31 15:25

Subject: need to create new repository initially seeded with several branches
Message-ID: <1314804325568-6746957.post@n2.nabble.com>
URL: https://gitlist.dev/e/1314804325568-6746957.post%40n2.nabble.com

```
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, 2011-08-31 15:40

Subject: Re: need to create new repository initially seeded with several branches
Message-ID: <201108311540.p7VFen5S015756@no.baka.org>
URL: https://gitlist.dev/e/201108311540.p7VFen5S015756%40no.baka.org
In-Reply-To: <1314804325568-6746957.post@n2.nabble.com>

```

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, 2011-08-31 16:10

Subject: Re: need to create new repository initially seeded with several branches
Message-ID: <CAKjsY4nsPNO_kvxeime8qcNrRFykgG2TOYxJ0HKbj2zR5Rwv+Q@mail.gmail.com>
URL: https://gitlist.dev/e/CAKjsY4nsPNO_kvxeime8qcNrRFykgG2TOYxJ0HKbj2zR5Rwv%2BQ%40mail.gmail.com
In-Reply-To: <201108311540.p7VFen5S015756@no.baka.org>

```
On Wed, Aug 31, 2011 at 8:40 AM,  <in-git-vger@baka.org> wrote:
>
> 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...

```

## Brandon Casey, 2011-08-31 16:14

Subject: Re: need to create new repository initially seeded with several branches
Message-ID: <sDZ5pnWzh3ZbFYS6GK-NcPdn09kF53MJ2eRkBnzInzdL8-cvCiF5beUw2k9Pz6BTq-Y3i_XwpYfgTOvXNlP1vPjLSHJ6FIzxL0jN1W0d0M8@cipher.nrlssc.navy.mil>
URL: https://gitlist.dev/e/sDZ5pnWzh3ZbFYS6GK-NcPdn09kF53MJ2eRkBnzInzdL8-cvCiF5beUw2k9Pz6BTq-Y3i_XwpYfgTOvXNlP1vPjLSHJ6FIzxL0jN1W0d0M8%40cipher.nrlssc.navy.mil
In-Reply-To: <1314804325568-6746957.post@n2.nabble.com>

```
On 08/31/2011 10:25 AM, ryan@iridiumsuite.com wrote:
> 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

```

## in-git-vger@baka.org, 2011-08-31 16:21

Subject: Re: need to create new repository initially seeded with several branches
Message-ID: <201108311621.p7VGLDlm015261@no.baka.org>
URL: https://gitlist.dev/e/201108311621.p7VGLDlm015261%40no.baka.org
In-Reply-To: <CAKjsY4nsPNO_kvxeime8qcNrRFykgG2TOYxJ0HKbj2zR5Rwv+Q@mail.gmail.com>

```

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

```

## Brandon Casey, 2011-08-31 16:45

Subject: Re: Re: need to create new repository initially seeded with several branches
Message-ID: <yOArP4qOaF5Yee5Bgcafl_795D9Xnz_IaUH21_GToggoTEy0uLzpGd3OA-rFJt2MlFFYbhvSBNDlv5C_GjSvXfcw7SRn4Ut12giha2cV4yM@cipher.nrlssc.navy.mil>
URL: https://gitlist.dev/e/yOArP4qOaF5Yee5Bgcafl_795D9Xnz_IaUH21_GToggoTEy0uLzpGd3OA-rFJt2MlFFYbhvSBNDlv5C_GjSvXfcw7SRn4Ut12giha2cV4yM%40cipher.nrlssc.navy.mil
In-Reply-To: <201108311624.p7VGOWWq018472@no.baka.org>

```
On 08/31/2011 11:24 AM, in-git-vger@baka.org wrote:
> 
> 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

```

## Jeff King, 2011-08-31 16:54

Subject: Re: need to create new repository initially seeded with several branches
Message-ID: <20110831165405.GB4356@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20110831165405.GB4356%40sigill.intra.peff.net
In-Reply-To: <sDZ5pnWzh3ZbFYS6GK-NcPdn09kF53MJ2eRkBnzInzdL8-cvCiF5beUw2k9Pz6BTq-Y3i_XwpYfgTOvXNlP1vPjLSHJ6FIzxL0jN1W0d0M8@cipher.nrlssc.navy.mil>

```
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

-Peff

```

## Brandon Casey, 2011-08-31 16:54

Subject: Re: Re: need to create new repository initially seeded with several branches
Message-ID: <b0jgmOi0Ah4tb2fbieP8wOLjAFkigcbyvh9ajtwoMITJ_sDaDBsfMmEh6_jv25UG4WpHCnhlXi0IFpVlkK9KuEOzDLz2r_l4pBt97stEDXg@cipher.nrlssc.navy.mil>
URL: https://gitlist.dev/e/b0jgmOi0Ah4tb2fbieP8wOLjAFkigcbyvh9ajtwoMITJ_sDaDBsfMmEh6_jv25UG4WpHCnhlXi0IFpVlkK9KuEOzDLz2r_l4pBt97stEDXg%40cipher.nrlssc.navy.mil
In-Reply-To: <yOArP4qOaF5Yee5Bgcafl_795D9Xnz_IaUH21_GToggoTEy0uLzpGd3OA-rFJt2MlFFYbhvSBNDlv5C_GjSvXfcw7SRn4Ut12giha2cV4yM@cipher.nrlssc.navy.mil>

```

@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>

```

## Brandon Casey, 2011-08-31 17:01

Subject: Re: need to create new repository initially seeded with several branches
Message-ID: <XWAITZ7y0RejBGQezy-miO4ykUsgbNWA0mNtHRto22msjs3PP6WSZlN-pPueaz0duxAP6dCio3ZH2lna0K_g79NKdL0q7sJbzjj8sEKicYM@cipher.nrlssc.navy.mil>
URL: https://gitlist.dev/e/XWAITZ7y0RejBGQezy-miO4ykUsgbNWA0mNtHRto22msjs3PP6WSZlN-pPueaz0duxAP6dCio3ZH2lna0K_g79NKdL0q7sJbzjj8sEKicYM%40cipher.nrlssc.navy.mil
In-Reply-To: <20110831165405.GB4356@sigill.intra.peff.net>

```
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

```

## Ryan Wexler, 2011-08-31 17:09

Subject: Re: need to create new repository initially seeded with several branches
Message-ID: <CAKjsY4kYm4ixTVQE4+8XZrf7DkAfn=ASoeMYob=5i1FmJ6eK5w@mail.gmail.com>
URL: https://gitlist.dev/e/CAKjsY4kYm4ixTVQE4%2B8XZrf7DkAfn%3DASoeMYob%3D5i1FmJ6eK5w%40mail.gmail.com
In-Reply-To: <XWAITZ7y0RejBGQezy-miO4ykUsgbNWA0mNtHRto22msjs3PP6WSZlN-pPueaz0duxAP6dCio3ZH2lna0K_g79NKdL0q7sJbzjj8sEKicYM@cipher.nrlssc.navy.mil>

```
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:
> 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
>

```

## Johannes Sixt, 2011-08-31 17:48

Subject: Re: need to create new repository initially seeded with several branches
Message-ID: <4E5E73D8.4040104@kdbg.org>
URL: https://gitlist.dev/e/4E5E73D8.4040104%40kdbg.org
In-Reply-To: <201108311540.p7VFen5S015756@no.baka.org>

```
Am 31.08.2011 17:40, schrieb in-git-vger@baka.org:
> # 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

```
