From: Chris Stankevitz 
  Cc: Chris Stankevitz ; Philip Oakley 
  Sent: Tuesday, September 25, 2012 8:01 PM
  Subject: Re: [git-users] Forcing a "push" from one branch to another

  On Tuesday, September 25, 2012 11:48:25 AM UTC-7, Philip Oakley wrote:
    Do you mean you want Branch 'b' drop its old line of development and become 
the same as Branch 'a'.
    Or you want Branch 'b' to gain a fresh commit who's content is identical to 
that on the tip of Branch 'a', but it would have a different history?


  Thank you for your help!

  My intention is for branch 'b' to gain a single commit whose diffs result in 
branch 'b' looking just like 'a'.  I attempted to say this by describing a 
series of laborious steps in my original post.
    There are a few different methods

  At this point, I'd be happy with whichever method will be easiest for you to 
type on this list.  Currently I am using the series of laborious steps in my 
original post.

    At the plumbing level you can simply create a commit on 'b' that simply 
uses the top tree from 'a', then do a `reset --hard` to make your worktree 
match that commit.

  Unfortunately I am not skilled enough to translate this sentence into a 
series of git commands.  Could you please either refer me to the documentation 
for the "top tree" command (as you call it) or just type out the commands that 
might do what I want?
The place to look for those internal details is:

Using it as a template we see that you should be able to use:
The master^{tree} syntax specifies the tree object that is pointed to by the 
last commit on yourmaster branch.


To create a commit object, you call commit-tree and specify a single tree SHA-1 
and which commit objects, if any, directly preceded it. Start with the first 
tree you wrote:

$ echo 'first commit' | git commit-tree d8329fyou'll write the other two commit 
objects, each referencing the commit that came directly before it:

$ echo 'second commit' | git commit-tree 0155eb -p fdf4fc3

You already have the tree on branch 'A', so it should be as simple as:

git update-ref refs/heads/B $(echo 'Copied from Branch A' | git commit-tree 
A^{tree} -p B)

Which is three steps in one:
1.   git commit-tree A^{tree} -p B    # create the commit with branch B as the 
2.   echo 'Copied from Branch A' |  # give it a message
3.   git update-ref refs/heads/B $(...)  # and update Branch B with the answer 
(sha1) from the commit created at 1.

I tested this on a simple dummy repo and it worked while I was on branch A. 

And Thanks for making me look properly ;-)

  Thank you again,


You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

Reply via email to