Ask Your Question
0

How is it possible to switch branches in Git without needing to stash local modifications?

asked 2023-05-29 23:03:42 +0000

nofretete gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-05-29 23:07:01 +0000

pufferfish gravatar image

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"
    
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-29 23:03:42 +0000

Seen: 7 times

Last updated: May 29 '23