git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Aaron Gray" <aaronngray.lists@googlemail.com>
Cc: "Git Mailing List" <git@vger.kernel.org>
Subject: Re: Duplicating a branch
Date: Tue, 02 Jun 2009 08:36:13 -0700	[thread overview]
Message-ID: <7voct6fy1e.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <BAF61FDE71D344FDB9F1415B5E2AFD75@HPLAPTOP> (Aaron Gray's message of "Tue\, 2 Jun 2009 16\:19\:36 +0100")

"Aaron Gray" <aaronngray.lists@googlemail.com> writes:

> How do I go about duplicating a branch within a repository, so I can
> make test mods ?

Run

    $ git checkout -b experiment master

to make a new "experiment" branch that points at the same comit as
"master" (or whatever other branch), hack away (including committing which
would grow the history of "experiment" branch without touching "master").

After you are done, and if you want to discard it, simply:

    $ git checkout master
    $ git branch -D experiment

or if you want to keep all of it:

    $ git checkout master
    $ git merge experiment

*BUT* if your "experiment" was truly exploratory in the sense that your
history is full of "let's try this, commit to snapshot, test, oops, it did
not work, let's try that, commit to snapshot, test, ok, I made some
progress, let's continue" crufts, you would most likely want to clean-up
your history before the latter "checkout master and merge experiment into
it" steps with something like:

    $ git rebase -i master experiment

If you in advance know that what you are going to do is truly "throw-away
experiment", you do not even need to use an "experiment" branch.  You can
do your exploration while on a detached HEAD:

    $ git checkout master^0

and hack away, including making commits (but you will discard them in
the end), and then finally:

    $ git reset --hard ;# if you have local changes you do not want to
			  take back to master
    $ git checkout master



    

  reply	other threads:[~2009-06-02 15:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-02 15:19 Duplicating a branch Aaron Gray
2009-06-02 15:36 ` Junio C Hamano [this message]
2009-06-02 16:50   ` Aaron Gray

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7voct6fy1e.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=aaronngray.lists@googlemail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).