need to create new repository initially seeded with several branches
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 message <[email protected]>, "[email protected]" 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
Am 31.08.2011 17:40, schrieb [email protected]:
Quoted 7 lines
# Cause git to delete all files in the internal index
git read-tree --reset -i4b825dc642cb6eb9a060e54bf8d69288fbee4904# 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
Quoted 46 lines · On Wed, Aug 31, 2011 at 8:40 AM, <[email protected]> wrote:
In message <[email protected]>, "[email protected]" 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 -i4b825dc642cb6eb9a060e54bf8d69288fbee4904# 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 -i4b825dc642cb6eb9a060e54bf8d69288fbee4904# 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:
Quoted 8 lines
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...
Quoted 10 lines · Ryan Wexler
# 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 -dfxThe 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
Quoted 10 lines · On 08/31/2011 10:25 AM, [email protected] 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 messageRepeat 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
Quoted 12 lines · Brandon Casey
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
Quoted 1 line
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
Quoted 28 lines · Jeff King
Quoted 12 lines · Brandon Casey
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 messageQuoted 1 line
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
Quoted 8 lines
# 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
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.
Quoted 42 lines · Brandon Casey
Quoted 28 lines · Jeff King
Quoted 12 lines · Brandon Casey
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 messageQuoted 1 line
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 commitQuoted 8 lines
# 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 -fBetter.
-Brandon
A message that is not in the archive (sent off-list or not yet received): uvMkLVapQYcSvOHVhcHX8CqGzEDajPEPvBbkL_DctzZvxm7aI-PjCQ@cipher.nrlssc.navy.mil
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 11 lines · On 08/31/2011 11:24 AM, [email protected] wrote:
In message <sDZ5pnWzh3ZbFYS6GK-NcPdn09kF53MJ2eRkBnzInzdL8-cvCiF5beUw2k9Pz6BTq-Y3i_XwpYfgTOvXNlP1vPjLSHJ6FIzxL0jN1W0d0M8@cipher.nrlssc.navy.mil>, Brandon Casey writes:
rm -rf * && # remove the files in the working dirI 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 rmalternatives 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
@Seth Robertson
Your email address seems to be broken. My message to you bounced:
----- The following addresses had permanent fatal errors -----
<[email protected]>
(reason: 550 5.1.1 <[email protected]>... User unknown)
----- Transcript of session follows -----
... while talking to tsutomu.baka.org.:
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
DATA
<<< 550 5.1.1 <[email protected]>... User unknown 550 5.1.1 <[email protected]>... User unknown <<< 503 5.0.0 Need RCPT (recipient)
----- Original message follows -----
<snip>