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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:59:57+00:00 2026-05-13T10:59:57+00:00

The common mistake I make in git is not check on which branch I

  • 0

The common mistake I make in git is

  1. not check on which branch I am
  2. commit changes to a wrong branch (on branch B, thinking I’m on A, commiting a change for feature A)

How do I get back, and commit the edits to the proper branch?

  • 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-13T10:59:57+00:00Added an answer on May 13, 2026 at 10:59 am

    rebase --onto can help here, especially if you have a range of commits to move back.

    Do not forget a git stash to save any current uncommitted changes which are relevant to “wrongBranch” (the one where commits were appropriately applied), in order to pop them back at the end of the process.

    Basically, you need to apply a commit or range of commits to another branch (called here “rightBranch“):

    # Checkout the right branch where the commit should have been applied
    git checkout rightBranch
    
    # Checkout a new temporary branch at the current location
    git checkout -b tmp
    
    # Move the rightBranch branch to the head of patchset which should have been on rightBranch
    git branch -f rightBranch last_SHA-1_of_commits_for_rightBranch
    
    # Rebase the patchset onto tmp, the old location of rightBranch 
    git rebase --onto tmp first_SHA-1_of_commits_for_rightBranch~1 rightBranch 
    

    (first_SHA-1_of_commits_for_rightBranch~1 is the parent commit of first_SHA-1_of_commits_for_rightBranch, that is the commit on top of which all the commits for rightBranch have been incorrectly applied)

    rightBranch will be again at the top of:

    • all the old commits of right branch (pointed by the tmp branch)
    • plus all the relevant commits range from wrongBranch, which have just been replayed on top of tmp (tmp being the previous rightBranch HEAD).

    Then you can reset wrongBranch to some previous commits.

    git checkout wrongBranch
    git reset --hard some_older_commit
    
    # if needed, re-apply what you were working on vefore this all proccess
    git stash pop
    

    Caveat:

    • cherry-picking or rebase –onto have consequences (see this question)
    • if wrongBranch has already been published (pushed to a public repo), that can be awkward for the people pulling for that repo (having to rebase all their changes on top of that “new” branch)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A common mistake when configuring the compilation/linking/etc. settings in VC++ 2008 is to set
The very common beginner mistake is when you try to use a class property
I'm rendering a common Log-In form using Html.RenderAction, on every page of my site.
I have what must surely be a fairly common documentation need... I'm implementing a
I was looking for solving a LCS problem (Longest common subsequence) and I tried
Most of our projects use a lot of common code. We are (finally) moving
I have several classes that conceptually belong to one tier. They have no common
This is sort of a follow up on this question I read: What is
I have a SQL Report that insists on printing an extra blank page at

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.