Home git How to switch between branches in Git when there are unsaved changes...

How to switch between branches in Git when there are unsaved changes in the current branch?

Author

Date

Category

I have a project. Located in the Project folder. Initializing Git, I create a new branch:

git init
Git Add.
Git Commit -m 'First Commit'
Git Branch Feature.
// Do something for Feature

What have I have? Two branches. One – Master . Other – Feature. They are distinguished.
I changed some files in the Project folder (while I worked in the Feature branch). But here it was very necessary to take a look at the files that in Master .

How to make in the Project folder there are not those files that I now work on Feature , but those that were in the Master ?


Answer 1, Authority 100%

If you already have a branch Feature , then after the commit to it, make Git Checkout Master – this will switch the current branch to Master .

While you have not made the changes, you cannot switch to another branch. Output two: composing changes or postpone them. The second can be done using Git Stash – this will add current uncomplete changes to the stack of change and reset the current workflow to head and the repository. Next you can:

  • Git Stash List : show all changes in the stack
  • Git Stash Show : show the last change in the stack (patch)
  • Git Stash Apply : Apply the last change from the stack to the current working copy
  • Git Stash Drop : Remove the last change in the stack
  • Git Stash Pop : Apply the last change from the stack to the current working copy and remove it from the
  • stack>

  • Git Stash Clear : Clean the Stack of Changes

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions