Let's say I have two files I am working on - "a.txt" and "b.txt". I need to commit my change to "b.txt" but want to keep working on "a.txt" for some more time. I do a "git add b.txt". Now, before I actually commit this change, is there a way to test that the commit will not break the master branch? If I run a test locally, the database tested in my local area would be different than that on master branch as I also have unstaged edits in "a.txt".

What is the standard procedure for testing in such situations (is it to use 'git stash'?). Or if this situation [needing to test commit in your local area when you also have unstaged edits] is not very common, how do developers avoid the same?

3 Answers 3


In general it does not really matter what you do before you push. It does not really matter to anyone else what your personal workflow is as long as you push according to the standards of your team.

In the case you described I would use git stash. In detail:

  1. commit b.txt
  2. stash other changes
  3. test
  4. push
  5. pop stash

A good practice is to always do work on branches (see Git Flow for one very common way to do so), and either execute a build against just that branch, or push the branch to a remote (e.g. Bitbucket/GitHub) and have it execute a branch build on your CI server. (Hopefully a build server is part of your development environment.)

The goal is to know that the master build will be green after you merge the branch by having executed the same build and test steps on the branch before you merge.


You only ever, ever push something that actually works. You may have files or changes that you were working on that you don't want to push. You must make sure that your branch that doesn't have these files or changes will work. Your branch may have additional changes made by someone else that may have broken your new code (which the person pushing those changes couldn't check for because they don't have your new code). So:

  1. Remove the changes that you don't want to push. Easiest done by using "stash" first, then removing the changes.

  2. Pull the latest state of the branch. Any conflicts are best handled at this time. Make sure that your code works with these changes.

  3. Push your complete code. You always push what you have tested. Obviously your complete code doesn't contain the bits that you didn't work.

Then you can use stash again to restore the changes you were working on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.