git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
BCBrandon Casey <brandon.casey.ctr@nrlssc.navy.mil>
Date
Aug 31, 2011, 16:14 UTC
Message-ID
<sDZ5pnWzh3ZbFYS6GK-NcPdn09kF53MJ2eRkBnzInzdL8-cvCiF5beUw2k9Pz6BTq-Y3i_XwpYfgTOvXNlP1vPjLSHJ6FIzxL0jN1W0d0M8@cipher.nrlssc.navy.mil>
In-Reply-To
<1314804325568-6746957.post@n2.nabble.com>
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
Previous: Johannes SixtNext: Jeff King
Message 6 of 11 in “need to create new repository initially seeded with several branches”
  1. ryan@iridiumsuite.comAug 31, 2011
  2. in-git-vger@baka.orgAug 31, 2011
  3. Ryan WexlerAug 31, 2011
  4. in-git-vger@baka.orgAug 31, 2011
  5. Johannes SixtAug 31, 2011
  6. Brandon CaseyAug 31, 2011
  7. Jeff KingAug 31, 2011
  8. Brandon CaseyAug 31, 2011
  9. Ryan WexlerAug 31, 2011
  10. Brandon CaseyAug 31, 2011
  11. Brandon CaseyAug 31, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.