Monday, July 14, 2014

Using Temporary Branches in Git

When you're working on something experimental or when you are interrupted and need to switch branch to work on something else and you don't feel that your code is ready to commit to a branch shared with other developers yet, you can create a temporary branch for your commits. Once you're done, you may merge the changes back into your original branch, or discard the changes when you subsequently delete the temporary branch.

Supposing you're currently working on something experimental on branch "dev" that you are not sure about, you may perform your commits on another branch:

Steps:

  • Create a new branch "dev-temp"
  • Checkout the new branch
  • Commit your code to "dev-temp"and continue to do so until you're done
  • After you are done, and if you want to merge your changes:
    • Switch to "dev"
    • Merge your changes from "dev-temp" to "dev"
  • Delete temporary branch "dev-temp" with "git branch -d dev-temp"
  • And if you've never pushed "dev-temp", then you don't have to worry about having to do it. It's your local temporary branch after all.

No comments:

Post a Comment