Posts tagged with “Git”

Using Git Branches as Patches

At Viddler, we’re now using Git for projects, and it’s going really well so far. While we haven’t figured out the perfect workflow just yet, we’re doing some things I really like, and one of them is treating branches like patches.

Often, people think of Git branches as a full copy of the parent branch, but it’s better to treat them as a simple collection of new commits, to be applied to the parent branch later. This might not seem too revolutionary, but this small change in thinking can really improve your workflow.

For example, at Viddler we use Trac to manage tickets, and in Git. For each ticket in Trac, we create a branch, called something like 3241-fix-embed-codes. We have two permanent branches: dev, which reflects current development, and master, which is considered always production-ready. So, dev and master are going to have different code to reflect their reflective stability. To get started with a fix, we first create a feature branch from master:

git checkout -b 3241-fix-embed-codes master

This simply creates a new branch of master called 3241-fix-embed-codes and checks it out. When the ticket is completed and the code has been committed, the patch thinking really comes into play. Since this now needs to be tested in the dev environment, the branch first gets applied to the dev branch:

git checkout dev
git merge —no-ff 3241-fix-embed-codes

Using the —no-ff option on git merge is important for this patch mindset: it creates a separate commit for the merge itself, which allows you to git revert the entire thing (if necessary), rather than having to undo each individual commit within it.

Once we’ve decided this fix is read for production, it’s time to move the code over to master. Without the patch mindset, you might consider merging dev into master, but that means you’d be copying anything that’s applied to dev, some of which might not yet be ready. When you think of your feature branch as a patch, however, it’s easy to only apply the one you need. To apply this patch to master, just use a similar method as before:

git checkout master
git merge --no-ff 3241-fix-embed-codes

Now you’ve only moved the safe commits over, leaving any buggy code safely in dev.

This method may seem obvious, but the mindset has really changed the way I use Git, and I think it makes it a much more powerful tool, especially when you’re working across multiple environments (like production and staging). I’ve skipped over some additional considerations, like merging master/dev into your feature branch, but those are topics for a future post.

Posted on May 6, 2010 2 Comments
Tagged with: , , , ,

Git Autocompletion in OS X

Add the source line to your ~/.profile or ~/.bash_profile to enable tab autocompletion of branch names, remotes, etc.

Posted on April 23, 2010 1 Comment
Tagged with: , , ,

A successful Git branching model

This is why I love Git so much: it makes complex workflows, like the one to which I’ve linked, really simple to implement. I can’t even imagine trying this in Subversion.

Posted on February 4, 2010 Leave a Comment
Tagged with: , ,

Why You Should Switch from Subversion to Git

Scott Chacon delves into why you should switch to Git. Once you switch to Git, make sure to try out my Git workflow.

Posted on September 15, 2009 Leave a Comment
Tagged with: , , ,

Compiling Ruby, RubyGems, and Rails on Snow Leopard

Dan Benjamin walks through how to install Ruby, RubyGems, and Rails on Snow Leopard. Also be sure to check out his other Snow Leopard guides for Mercurial, Git, and MySQL.

Posted on September 1, 2009 Leave a Comment
Tagged with: , , , , , , , ,

Rebase like a boss

Nick Quaranto on why you should rebase instead of merge when using Git:

Everyone who loves Git hopefully loves branching. However, there’s a problem with branching: merging your work back in. Suprisingly enough, Git’s inflexibility makes this action quite simple. It’s my opinion that Git users should be branching frequently, and rebasing them back into the mainline when ready.

This is my basic philosophy when using Git: the cleaner you keep your history graph, the better.

Posted on August 18, 2009 Leave a Comment
Tagged with: , , ,

Beanstalk will support Git

Over on the Beanstalk blog, Chris Nagele announces that Beanstalk will be supporting Git. We use Beanstalk at Viddler–it’s a superb application, and adding Git will make it even better.

Posted on August 12, 2009 Leave a Comment
Tagged with: , , , ,

The Perfect Git Workflow for a One Person Project

A few months ago, I started investigating Git, and I fell in love with how much easier it made managing my code. I’m managing the source code to this site with Git, and along the way I’ve come up with a pretty good workflow for myself. The basic steps are:

  1. Branch
  2. Commit
  3. Rebase
  4. Merge
  5. Deploy

Let’s go through each one to see how it all works together.

Branch

With SVN, I found myself hating branching–it was always a complicated procedure, and I could never remember how to do it. In Git it’s as easy as git checkout -b <branch-name>, and you’re ready to go. Once you have a branch, you can modify it however you want, and you don’t have to worry about interfering with the master branch. In order to keep your master branch bug free, commit only to branches, not to master itself.

In addition to creating new branches for major features, I always have a few branches around that I pop into for certain things:

  • “design” - any changes I want to make to the design go here
  • “optimize” - optimizations to the site
  • “bugfixes” - a place to work on minor bugfixes

Having these branches allows me to make small fixes to the site, and if it turns out it’s more than just a small fix, it doesn’t interfere with anything else.

Commit

In the Subversion world, it’s a pretty common practice to make very large commits, consisting of many changes. With Git, you should constantly be committing. By making many commits, you make it easier to find bugs you may have introduced, and it makes it a lot easier to track your progress. If you don’t like the thought of wading through long lists of commits in your logs, don’t worry–before bringing it over to the master branch, you can consolidate things with interactive rebasing, but while you’re hacking away on a branch, it really is advantageous to have many small commits.

Rebase

Rebasing is one of the harder things to grasp when you’re first learning about Git. For in-depth coverage of the topic, check out the Rebasing page in the Git Community Book. In a nutshell, doing git rebase master takes any commits to master and inserts them into your current branch, so you can then make sure your new code still works, and it’s a lot less hazardous than doing a merge. Rebasing your branch before putting into master is really important because it allows you to deal with any merge issues before the code goes to your main branch. To rebase, just run git rebase master.

Merge

After rebasing the branch, it’s safe to merge it into master. Since I’ve already dealt with any merge issues with the previous step, it’s as simple as checking out the master branch and running git merge <branch-name>

Deploy

I use Capistrano to deploy my code, so I’m constantly typing git push followed by cap deploy to deploy changes to my server. To make it easier, I just put both commands into one git alias:

deploy = !git push && cap deploy

Now I just need to run git deploy and it automatically pushes all of my changes to the remote Git repository and then deploys the site using Capistrano. Here’s some more information about Git aliases.

Useful tools

Though I primarily use Git through the command line, I really like using GitX to visualize branches. To host my repositories on my server, I use Gitosis, though if I had a few more projects, I’d dole out the money for a paid account at GitHub.

Have a great Git workflow? Think mine’s terrible? Let me know in the comments!

Posted on July 30, 2009 5 Comments
Tagged with: , , , ,

Deploying ExpressionEngine from GitHub with Capistrano

Dan Benjamin takes you step-by-step through deploying ExpressionEngine from GitHub with Capistrano in a really in depth tutorial. I’m definitely going to have to set this up for my EE sites.

Posted on June 2, 2009 Leave a Comment
Tagged with: , , , , ,

A Git Workflow for Agile Teams

Rein Henrichs does a great job explaining an agile git workflow for teams, and I found it to be very helpful, even for my 1-person projects (e.g. this site). I’ve always been a little confused as to when I should rebase and when I should merge, but after reading through this, it makes a little more sense now.

Posted on March 9, 2009 Leave a Comment
Tagged with: , , ,

The Thing About Git

Great post by Ryan Tomayko about some more advanced Git topics involving the commit staging area, or the “index.” I have fallen completely in love with Git, and I love all the little extra things I keep learning about.

Posted on January 19, 2009 Leave a Comment
Tagged with: , , ,

A Gaggle of Git Tips

Some great tips for working with Git from the team over at Viget

Posted on January 12, 2009 Leave a Comment
Tagged with: , ,