Wednesday, December 8, 2010

Creating/Deleting local and remote branches with git

In the course of my git-based workflow, more often than not, I use branches like this:

  • Create a new local branch starting from the HEAD of my current working branch.
  • Immediately push it upstream to the remote origin so that it exists in both places.
  • Set the local branch to track the remote branch.
  • Commit/push/repeat
  • Merge the branch back into master (or wherever it started from)
  • Delete the local branch.
  • Push to delete the remote branch.
Since this seems pretty common, and some of the commands to do this are a bit difficult to remember sometimes, I created two simple scripts called git-branch-create and git-branch-delete to help with this. Now my workflow looks like:

  • git branch-create feature_branch
  • Commit/push/repeat.
  • Merge branch back into parent branch.
  • git branch-delete feature_branch

To use these scripts via the above commands, download the scripts above and place them somewhere in your path. I even created short aliases for them like so:


No comments: