Committing before pulling is not always advisable -- you should consider stashing your work instead.
A better way to think about this is in terms of your staging area. Ideally, you'd like it to be clean before you attempt to merge in remote changes (remember, git pull
= git fetch
+ git merge
).
git commit
is one way of accomplishing this, but it will alter your history--thereby polluting it if you're concerned about leaving your repo in a constantly working state.
git stash
, on the other hand, was built for use cases just like this.
Use git stash when you want to record the current state of the working directory and the index, but want to go back to a clean working directory.
source: http://git-scm.com/docs/git-stash
You workflow would then look something like this:
$ git stash
$ git pull origin master
$ git stash pop stash@{0}
This will allow the pull to execute without issues, vocally warn you when applying your stash has resulted in conflicts.