Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Git allows you to switch branches without stashing local modifications by committing the changes to the current branch, checking out the new branch, and then cherry-picking the commit that contains the changes.

  1. Commit changes to the current branch: git add . git commit -m "commit message"
  2. Switch to new branch: git checkout new_branch
  3. Cherry-pick the commit that contains the changes: git cherry-pick commit_ID
  4. If there are merge conflicts, resolve them and commit the changes. Otherwise, continue working on the new branch with the changes intact:

    git add .
    git commit -m "merged changes from previous branch"