Skip to main content

Command Palette

Search for a command to run...

Git issue - move specific commits from your current branch to a different branch

Published
1 min read
Git issue - move specific commits from your current branch to a different branch

There are multiple ways to move branches from one branch to another.

  1. Cherry-pick only copies the commit from current branch to target branch rather than moving the commit i.e., the branch is still there in source branch.

     # Switch to the target branch
     git checkout target-branch
    
     # Cherry-pick specific commit(s)
     git cherry-pick <commit-hash>
    

    This is the first way, but as mentioned earlier - this would only copy the commit but not move it.

  2. In order to move the commit, we need to use rebase:

     # Move to the source branch
     git checkout source-branch
    
     # Start an interactive rebase
     git rebase -i HEAD~<N>
    
  • Change pick to drop for commits you want to remove from the source branch.

  • Save and exit.

      git checkout target-branch
      git cherry-pick <commit-hash>
    

    This removes the commit from the original branch and moves it to the correct branch.

Git Issues & Fixes

Part 2 of 2

This series covers common Git issues like merge conflicts, detached HEAD, and rebase mistakes. Each post explains the problem, its cause, and step-by-step fixes to keep your workflow smooth. Perfect for beginners and experienced developers alike!

Start from the beginning

Git Issue - Committing the password to Remote Repo

There are high chances that beginners at times commit secrets, sensitive information or password to remote repo accidentally. In this article, we will see how we can revert back the accident. Also, we will see how we can make sure this won’t be repea...