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

Re: How to find where a branch was taken from.

From
Charles Bailey <charles@hashpling.org>
Date
Mar 21, 2008, 18:32 UTC
Message-ID
<20080321183225.GA13583@hashpling.org>
In-Reply-To
<32541b130803211039h1f5b8da5k8fb353d46e57b05e@mail.gmail.com>
On Fri, Mar 21, 2008 at 01:39:11PM -0400, Avery Pennarun wrote:
Show 22 quoted lines
> On Fri, Mar 21, 2008 at 5:13 AM, Junio C Hamano <gitster@pobox.com> wrote:
> > Paul Gardiner <osronline@glidos.net> writes:
> >  > I need a command that will find the remote branch from which
> >  > the currently checked out branch was started. I don't know
> >  > git very well, and the only way I can think to do it so far
> >  > is to iterate over the remote branches and find the one
> >  > for which git-rev-list <branch>..HEAD gives the smallest
> >  > number of objects. I'm guessing there must be a better
> >  > way. Any ideas?
> >
> >  There will be _no_ way.  It is simply impossible.
> >
> >     $ git checkout -b my-new-branch origin/somerandombranch~27^2^2~23
> >
> >  is a perfectly valid way to create a new branch.
> >
> >  You would probably want to re-think in a bigger picture, _why_
> >  you would want to find such information, [...]
> 
> I frequently want to do this.  Basically, I start from "some version"
> of the upstream program, and I put together some patches, then I want
> to use rebase to reorder and recombine them before I send them in.
So you're looking to do a git rebase -i?
Show 6 quoted lines
> In order to do this, however, I'm forced to remember where I got my
> "original" version from, which isn't even that important.  As the
> developer of a particular patch, all I *really* should have to know
> is: a) here are the things I added since I made my topic branch, and
> b) here is the branch I want to rebase them onto so I can submit my
> cleaned patches upstream.
Why are you forced to remember?

If you don't want to transplant the patches onto where the remote branch is now, then you just need to pick a commit on your current branch that is before any commit that you want to reorder/recombine and do a git rebase -i <sha1>. (It should be easy to pick a commit from git log. Perhaps it's the first one with and author that isn't you. Alternatively, if you don't want to look at the log and you know you haven't made more than N commits you could just git rebase -i HEAD~N.)

If you want to rebase them on to the latest version of the remote branch then it's even simpler. You just do:

git rebase -i remote/branch

I'm not sure I understand why you need to know where your original branch was made from?

Charles.
Previous: Avery PennarunNext: Avery Pennarun
Message 5 of 12 in “How to find where a branch was taken from.”
  1. Paul GardinerMar 21, 2008
  2. Junio C HamanoMar 21, 2008
  3. Junio C HamanoMar 21, 2008
  4. Avery PennarunMar 21, 2008
  5. Charles BaileyMar 21, 2008
  6. Avery PennarunMar 21, 2008
  7. Dmitry PotapovMar 21, 2008
  8. Daniel BarkalowMar 21, 2008
  9. J. Bruce FieldsMar 21, 2008
  10. Paul GardinerMar 22, 2008
  11. Jeff KingMar 22, 2008
  12. Paul GardinerMar 22, 2008

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.