My Essential Git Workflow

This workflow is the core of my daily work in git.

  • There's more here than the bare minimum needed to work in git, but...
  • This workflow enables us to do more later, and to work more productively.

We'll look at what this enables in later posts; for now, here's the workflow itself.

Start off by creating a new local branch (explained later in this post):

[object Object]

Work locally & commit changes on that branch frequently.

To keep integrated with upstream code, first update the master branch. Before continuing, all changed files must be committed to your local branch, stashed or rolled back. Then update master:

[object Object]

Now that master is updated, switch back to our local feature branch & rebase it (not merge) on top of master.

[object Object]

Resolve any merge conflicts. Now your local branch is updated with the upstream code. Rebuild & test, then repeat the change-commit-rebase cycle until you're all done with that feature.

When you're ready to push your new feature upstream, repeat the fetch & rebase-from-master steps to make sure your new code is based on the latest upstream code.

When you're ready to push your code upstream, merge (not rebase this time!) back to master and push:

[object Object]

If you're done with the local branch, delete it:

[object Object]

And that's the whole workflow in a nutshell.

There are a few key points to remember:

  • Work on a local branch
  • Rebase out from master to get updates
  • Merge back to master only when you're ready to push upstream

After doing this a few times, I think you'll find that it flows easily.

There is more here than the bare minimum that's needed to work with git. That's because this workflow enables us to do more later. A lot more. It will enable us to be effective & productive in new ways, not just do the bare minimum to scrape by. (I'll explore this more in future posts.)

Try out the steps in this workflow. I think you'll find that it's really fairly simple in practice: there are a few different stages, and you really only need a couple of commands for each stage. So give it a try.