Some time ago I pulled master
. I then created a branch off of master, branch1
. I've done quite a bit of work in branch1
. I have several commits, and since my last commit I have changed a lot of files and added new files, possibly deleted some files. So my working directory is currently not clean.
Someone else has now merged a bunch of changes into master on the server, and I need to pull those changes to master and rebase my work.
In order to rebase branch1
to the latest master
, do I need a clean working directory? In other words, do I need to commit my current work before rebasing? I'm not clear how this works.
Yes, you should have a clean working directory before you rebase (or switch branches if you intend to checkout master). The simplest way to achieve this is to just commit whatever you have right now. Note it doesn't matter if you aren't ready to commit because it isn't done. Just set your commit message to something to remind you it isn't finished. For example, I use "wip - some quick note here". And since I always start my commits with a capital letter for actual commit titles, I use a lowercase starting letter to indicate to me that I need to rebase/amend/reword the commit before I create my pull request. If for some reason you are dead set against committing unfinished work (I can't think of any good reason for this), then you could stash your changes instead to get a clean directory.
Tip: delete your local master branch, as you (probably) never will need it. If you want to rebase onto master, you don't need to do what you implied you were going to do, which is: checkout master, pull the changes, then checkout your branch, and then rebase onto master. Instead, just git fetch, and then rebase onto origin/master. It's much faster and achieves the identical result. Anytime you want to create a new branch off of master, git fetch, then create your branch off of origin/master.