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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:49:43+00:00 2026-05-23T08:49:43+00:00

Working with git, after some ‘commit’, and a couple of ‘push’, I realized that

  • 0

Working with git, after some ‘commit’, and a couple of ‘push’, I realized that am using the wrong branch!

Now I have to remove in some way my changes in wrong_branch
and commit and push the changes in right_branch

What’s the best (and simple) way to do that ?

  • 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-23T08:49:44+00:00Added an answer on May 23, 2026 at 8:49 am

    switch to that branch, check the git log and git revert those commits individually. Once you have done that, switch back to the desired branch and there you can then use git cherry-pick to pick specific commits from the git refs and merge it into the right branch.

    git checkout wrong_branch
    git revert commitsha1
    git revert commitsha2
    git checkout right_branch
    git cherry-pick commitsha1
    git cherry-pick commitsha2
    

    If the commits are grouped together and there are no commits pushed after your dirty commits, you can even use git reset to get that wrong branch to a state just before your commits and then follow that again using git cherry-pick to get your commits into the right branch.

    git checkout wrong_branch
    git reset commitsha3 #commit just before commitsha2
    git checkout right_branch
    git cherry-pick commitsha1
    git cherry-pick commitsha2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's an example: >git status # On branch master nothing to commit (working directory
After working for some time with SVN I decided to try git with my
I am working on a git repository with a master branch and another the
I'd been working on something, and decided it was completely screwed...after having committed some
After a pull, git status tells me that I have changed a 16Mb xml
I'm working on a project where some people will sent me git patches and
I just got a Mac after working with Ubuntu Linux for some time. Among
So, after converting my repository to git and doing the first build, some build
I reverted to a previous commit and made some changes. Now I want to
I am working through some tutorials for git and don't understand the difference between

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.