Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 380299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:58:32+00:00 2026-05-12T14:58:32+00:00

In my git repository, I have merged branch B into master, getting the the

  • 0

In my git repository, I have merged branch “B” into “master”, getting the the following structure:

--> A --> B --> C --> D  (branch master)
    |           |  
    F --> G --> H        (branch B)

I now want to combine the branches to get the following history:

--> A --> B --> F --> G --> H --> D

How can I do this?

Regards,
Jochen

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T14:58:32+00:00Added an answer on May 12, 2026 at 2:58 pm

    I assume C is a merge commit, and that’s the reason you don’t want to have it in your result.

    What you need, to do what you want, is git rebase

    Let’s start of with yet another schematic commit graph. To leave the original
    branches intact we will operate on a new branch called rebasing

    git checkout -b rebasing master
    
    --> A --> B------------------- --> C --> D         (branch master) (branch rebasing)
         \                           /
          +----+->  F --> G --> H -+                   (branch topic)
    

    Just rebase everything between topic and rebasing onto topic.

    git rebase --onto topic topic rebasing
    

    or do the same with a shorter command

    git rebase topic
    
    -> A -> B -----------------> C -> D                (branch master)
        \                      /
         +---+>  F -> G -> H +                         (branch topic)
                              \
                               +---------> B -> D      (branch rebasing)
    

    Now when we just look at rebasing we have a straight line form A to D.

    -> A -> F -> G -> H -> B -> D                      (branch rebasing)
    

    So, the only problem right now might be that the order is different from what
    you expected. You could easily fix that by reordering commits with git rebase
    --interactive
    , if you want to.

    Or you rebase everything in a slightly more complicated way. Let’s start again.

    --> A --> B------------------- --> C --> D         (branch master) (branch rebasing)
         \                           /
          +----+->  F --> G --> H -+                   (branch topic)
    

    First take everything from C to the tip of master (aka. D) and put it on the
    tip of topic (aka. H) :

    git rebase --onto topic C master
    
    -> A -> B ----------------> C -> D                (branch master)
        \                      /
         +----> F -> G -> H +                         (branch topic)
                              \
                               +---------> D           (branch rebasing)
    

    One last rebase, at the end, and we are finished.

    git rebase B
    
         +----> F -> G -> H +                         (branch topic)
        /                     \
    -> A -> B ----------------> C -> D                (branch master)
             \
              +------------------------> F -> G -> H -> D   (branch rebasing)
    

    Voila!

    -> A -> B -> F -> G -> H -> D                      (branch rebasing)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a number of branches in a git repository: david@Panama ~/app: git branch
So we've gotten a git branch into a tricky state: Two branches: * master
Say I have a git repository and I've been working on master, can I
I have a git repository with multiple branches. How can I know which branches
I have a Git repository which contains a number of subdirectories. Now I have
I'm having problems getting hudson to checkout my git repo and merge into master.
I have a git repository with remote foo. foo is a web app, is
I have a git repository which tracks an svn repository. I cloned it using
I have a Git repository I store random things in. Mostly random scripts, text
I have a local git repository which tracks a remote SVN repository via git

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.