Created a branch from a remote branch for a quick fix, but git status shows my modified files that I had in my previous working branch
I was working on a feature (on my local master branch), git status showed me that I have 3 modified files uncommitted. That’s ok. Then I noticed a bug on the live site. I wanted to abandon my current work, and create a quick fix for the bug.
I created a branch from the remote repo’s master:
git checkout -b quickfix origin/master
But git status shows that I have 3 modified files. Why is that? I made no update on any files, only created the branch from the remote.
I just want to have a clean branch from remote/master that I can start working on with the quickfix.
2 Solutions collect form web for “Created a branch from a remote branch for a quick fix, but git status shows my modified files that I had in my previous working branch”
stash your changes, so they are stored in a “floating” commit, and then you can apply them back after you work on your bugfix:
$ git stash save "Working on ... - going to bugfix" $ git status --short # should show only untracked files $ git checkout bugfix # work work work $ git add file1 $ git commit $ git push # probably a merge and that $ git checkout master $ git stash pop # applies the last stash's changes to working copy
Git won’t delete files just because you switched a branch – that’s good, you wouldn’t want to lose them.
This is what I would do (starting from the branch :
git add --all git stash git checkout quickfix # do all the work you need to fix the problem and commit git checkout master git stash pop # apply stashed work and remove it
Git stash saves the changes you made and you may reapply them later after you’re done fixing other things (you can apply stashed work to different branches and more than one time if you need to).