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

  • SEARCH
  • Home
  • 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 6530997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:49:27+00:00 2026-05-25T09:49:27+00:00

I have two branches, master and feature1. I was working on feature1 when I

  • 0

I have two branches, master and feature1. I was working on feature1 when I realized that I needed to work on something else unrelated. Unfortunately, I forgot to branch from the master, and instead created my feature2 branch from feature1. Now I want to merge feature2 into master, but cannot because there are parts of feature1 in that branch.

How do I remove the feature1 commits from the feature2 branch? Does it involve rebasing?

I feel that if I could change the starting reference point of feature2 to be where master is, that might help, but have no idea how.

EDIT:

Thank you for the answers! I tried rebasing according to @Mark’s solution, but realized that the history is more complicated than I originally thought. feature 2 has been merged into other feature branches, and master was merged into feature2 at one point. There are also additional commits on master that are not related to feature2 Everything is still local.

Really, my history is more like this:

A - B - C - D - - - - - - - - - - - - - L - M  master  
            |                          
            |               - I - J - K  feature2                  
            \              /           \
             - E - F - G - H - - - - - -N - O - P  feature1

And what I want is this:

A - B - C - D - - - - - - - - - -  L - M  master
            |\                          
            |  - - - - - I - J - K  feature2                  
            \                     \
              - E - F - G - H - - - N - O - P  feature1

I have also tried:

git rebase --onto 1524b824cfce5856a49e feature1 feature2
// 1524b824cfce5856a49e == D

But this just sets the branch name feature 2 pointing at 1524, and leaves commits I, J, K with their original parents.

  • 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-25T09:49:28+00:00Added an answer on May 25, 2026 at 9:49 am

    If it’s only you working on your feature2 branch and you haven’t shared it with other people, it’s fine to rebase that branch before merging. You could do the following, for example:

    git checkout feature2
    git rebase --onto master feature1 feature2
    

    … which will rewrite your feature2 branch, leaving it so that it consists of all the commits in feature2 since it was branched from feature1, but reapplied onto master. I suggest you use gitk --all or a similar git history viewer afterwards to check that the result of this operation is what you want.

    Incidentally, this is exactly the scenario used to explain --onto in the git rebase documentation – see the paragraph beginning:

    Here is how you would transplant a topic branch based on one branch to another, to pretend that you forked the topic branch from the latter branch, using rebase –onto.
    […]


    Updated in response to more material in the question:

    Starting with your history, which looks like this:

    A - B - C - D - - - - - - - - - - - - - L - M  master  
                |                          
                |               - I - J - K  feature2                  
                \              /           \
                 - E - F - G - H - - - - - -N - O - P  feature1
    

    You can get what you want by doing the following:

    git checkout feature2
    git rebase --onto D H feature2
    

    This will leave you with history that looks like:

    A - B - C - D - - - - - - - - - - - - - - - - - - - L - M  master  
                |\
                | \ - I' J' K' feature2       I - J - K                    
                \                           /           \
                 - - - - - - - E - F - G - H - - - - - -N - O - P  feature1
    

    Before creating the merge that you want in feature1, you should note down the SHA1sum of O and P. (I’m assuming N is just a normal merge, and not an “evil merge”.)

    Then do a hard reset to move feature1 back to H:

    git checkout feature1
    git rest --hard H
    

    Then you should have the history:

    A - B - C - D - - - - - - - - - - - - - - - - - - - L - M  master  
                |\
                | \ - I' J' K' feature2
                \
                 - - - - - - - E - F - G - H feature1
    

    Now you apparently want to merge K' into feature1:

    git merge K'
    
    A - B - C - D - - - - - - - - - - - - - - - - - - - L - M  master  
                |\
                | \ - I' - J' - - - - - - - K' feature2
                \                             \
                 - - - - - - - E - F - G - H - Z feature1
    

    And finally you can cherry-pick the old O and P onto feature1 with:

    git cherry-pick O
    git cherry-pick P
    

    … to leave:

    A - B - C - D - - - - - - - - - - - - - - - - - - - L - M  master  
                |\
                | \ - I' - J' - - - - - - - K' feature2
                \                            \
                 - - - - - - - E - F - G - H - Z - - O' - P' feature1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

lets say i have two branches master develop in master i have something like
In GitHub, I have two branches working and master branch. Now I wanted to
I have two branches, master and feature . I finished working on feature ,
I have two branches, master and dev. I always work on dev and only
I have two branches master and exp i tried to cherry pick some of
I have a git repository (at github.com) with two branches: master and gh-pages. I
Imagine the following situation: I have two branches: DEV and MAIN. I'm working on
Given that two branches have diverged and a specific commit from one branch (and
I have two branches in my Git repository: master seotweaks (created originally from master
I have two branches to my project, master and test branches . when I'm

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.