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 8868111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:11:19+00:00 2026-06-14T17:11:19+00:00

I have a feature branch where I have some commits. Then I did run

  • 0

I have a feature branch where I have some commits. Then I did run git rebase master and merged that branch back to master.

So it was like

git checkout -b somebranch
......some work commits here .....
git checkout master
git fetch
git merge origin/master
git checkout somebranch 
git rebase master
git checkout master
git merge  somebranch

Now I need to pull out all my commits in somebranch out from master completely, possible will need to merge it back to master later.

Update: changes were pushed to master some time ago and there is many commits after merge, so reset to head will not work

  • 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-06-14T17:11:21+00:00Added an answer on June 14, 2026 at 5:11 pm
    git checkout -b somebranch # from "A"
    ......some work commits here x, y, z .....
    git checkout master
    git pull # call new HEAD "B"
    

    So we have something like

    A -> a1 -> a2 -> B <= master
     \
      x -> y -> z      <= somebranch
    

    and then:

    git checkout somebranch 
    git rebase master
    
    A -> ... -> B <= master
                 \
                  x' -> y' -> z' <= somebranch
    
    git checkout master
    git merge  somebranch # call new HEAD "C"
    
    
    A -> ... -> B -------------> C <= master
                 \              /
                  x' -> y' -> z' <= somebranch
    

    So, at this point, you can easily undo your unwanted merge, by just rewinding master to B. However, once you push C (and other people have seen it, and/or done work on top of it), this becomes hard.


    The simple solution is to just revert all commits on somebranch:

    git revert x'..z'
    

    and push.

    Now, before you can merge somebranch again, you’ll have to rebase it (like you did originally). This works, but you do end up with some noise in the history of master.


    If a limited number of people have seen and/or committed children, and you can coordinate with them, it’s possible to avoid this, but it’s a lot of work.
    You have to make sure everything they’re working on is committed and pushed if possible, and then you can rebase this:

    A -> ... -> B -------------> C -> c1 -> c2 -> D <= master
                 \              /
                  x' -> y' -> z' <= somebranch
    

    to this:

                  c1' -> c2' -> D' <= master
                 /
    A -> ... -> B -------------> C -> c1 -> c2 -> D
                 \              /
                  x' -> y' -> z' <= somebranch
    

    Now the middle branch will be orphaned, the new head D' doesn’t have your changes, and somebranch is still intact so you can merge later.

    To do this, use:

    git rebase --onto B C c1
    git push --force
    

    Everyone else will now have to update to the new head D', for example by doing:

    git fetch
    git checkout master
    git reset --hard origin/master
    

    Note that if anyone does have local commits that still depend on C (and aren’t already visible in the c1..D chain when you rebase), they’ll need to rebase or cherry-pick them across to the new history. This is potentially a lot of (error-prone) work, so better to avoid if possible.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In master I have some files that should better live in a feature branch.
I have a master branch that was branched from by another dev, who then
Suppose I have this feature branch foo. Now I want to merge it back
I have a git tree that looks like the following: Because of the review
I am working on a feature branch and have some changes committed to my
I have a feature branch and a master branch. My feature branch was checked
We have worked on a feature branch the last six months. Most commits made
We have some feature branches that can get put on ice for a few
I'm new to Git and a bit confused. I have a Master branch and
Background: I have a feature branch A that is one commit ahead of my

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.