A colleague informs you that a new feature has been added to a project, and it's available on the 'feature-login' branch for preview before it's merged into the main codebase. You are currently on the 'main' branch and have made some local modifications that you don't want to commit yet. How would you switch to the 'feature-login' branch to review the new additions without losing your uncommitted changes?
git merge feature-login into your main branch
git commit -m 'Temp commit' and then use git checkout feature-login
git stash your changes and then use git checkout feature-login
The correct answer is git stash your changes and then use git checkout feature-login. This is because you can save your uncommitted changes with git stash, which acts like a stack where you can push changes to be temporarily stored, and later you can pop them off. After stashing your changes, you can safely change branches using git checkout. Using the other commands might either lead to a loss of local changes or are not correct commands for handling a change in branches.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What does 'git stash' do exactly?
Open an interactive chat with Bash
What is the purpose of using 'git checkout'?
Open an interactive chat with Bash
What happens if you just use 'git checkout feature-login' without stashing?