Opscode
Home     Introduction to Chef     Cookbooks     Blog     GitHub     Tickets 

Working with Git

compared with
Current by Barry Steinglass
on Aug 04, 2010 00:13.

Key
This line was removed.
This word was removed. This word was added.
This line was added.

Changes (2)

View page history
h1. Initial setup of development repository
# Setup a github account
# Fork the repositories
!Picture 1.png!
# Clone the repositories locally
{code}
$ git clone git@github.com:yourgithubusername/chef.git
{code}
# Add an opscode remote
{code}
$ git remote add opscode git://github.com/opscode/chef.git
{code}
You'll be able to see if this is successful with git config:
{code}
$ git config --get-regexp ^remote\.opscode
remote.opscode.url git://github.com/opscode/chef.git
remote.opscode.fetch +refs/heads/*:refs/remotes/opscode/*
{code}
# Adjust your branch to track the opscode master remote branch, by default it'll track your origin remote's master:
{code}
$ git config --get-regexp ^branch\.master
branch.master.remote origin
branch.master.merge refs/heads/master
{code}
Change it with the following
{code}
$ git config branch.master.remote opscode
{code}

h3. Optional: Delete your remote master branch
You don't need one! +You should never develop on 'master'+, all development should be topic-based (see below)
{code}
$ git push origin :master
{code}

h2. Keeping your 'master' up-to-date!
Once all this is done, you'll be able to keep your local master up to date with the simple command:
{code}
$ git checkout master
$ git pull --rebase
{code}
Alternatively, you can synchronise your master from any branch with the full fetch/rebase syntax:
{code}
$ git fetch opscode
$ git rebase opscode/master master
{code}

Using rebase pull will do a rebase instead of a merge, which will keep a linear history with no unecessary merge commits. It'll also rewind, apply and then reapply your commits at the HEAD.

Use [this Rakefile|^Rakefile] to update chef, ohai and cookbooks repos (edit as needed).

h2. Working on topic branches

So you wanna do some work?

# Create an appropriately named tracking branch!
{code}
$ git checkout --track -b CHEF-XX opscode/master
{code}
Setting a topic branch up to track opscode/master allows you to easily rebase your commits in preperation for merge.
# Do work
{code}
hack
hack
{code}
# Commit (see step two if more work remains)
{code}
$ git status
$ git commit <filespec>

{code}
# Rebase your commits against opscode/master
With your work done in a local topic branch, you'll want to assist upstream merge by rebasing your commits. You can either do this manually with 'fetch' then 'rebase', or use the 'pull --rebase' shortcut. You may encounter merge conflicts, which you should fix and then mark as fixed with 'add', and then continue rebasing with 'rebase --continue'. At any stage, you can abort the rebase with 'rebase --abort' unlike nasty merges which'll leave files strewn everywhere.
{code}
$ git fetch opscode
$ git rebase opscode/master CHEF-XX
{code}
# Rebase your commits with the tracking-branch shortcuts (handy dandy)
{code}
$ git pull --rebase
{code}
# Push a remote branch
{code}
$ git push origin CHEF-XX
{code}

h2. Job's done!
Don't forget to send a pull request and update the ticket. Once your work has been merged by the branch maintainer, it will no longer be necessary to keep the local branch or remote branch, so you can remove them!
a

# Sync your local master up:
{code}
$ git checkout master
$ git pull --rebase
{code}
Remove your local branch using -d to ensure that it has been merged by upstream. Branch -d will not delete a branch that is not an ancestor of your current head. From the git man page:
{code}
-d

Delete a branch. The branch must be fully merged in HEAD.
-D

Delete a branch irrespective of its merged status.
{code}
# Remove your local branch
{code}
$ git branch -d CHEF-XX
{code}
# Remove your remote branch by using the full syntax to 'push', and omitting a source branch.
{code}
$ git push origin :CHEF-XX
{code}
This page has been permanently moved to http://wiki.opscode.com/display/chef/Working+with+git

Copyright © 2009 Opscode, Inc. All Rights Reserved.