Skip to content

Instantly share code, notes, and snippets.

@conf
Created March 22, 2012 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save conf/2165086 to your computer and use it in GitHub Desktop.
Save conf/2165086 to your computer and use it in GitHub Desktop.
PHP workflow with multiple checked out branches

Clone repository

cd 
git clone git@git.php.net:php-src.git

or if you're behind firewall

cd
git clone https://git.php.net/repository/php-src.git

Find git-new-workdir script

Find git-new-workdir script, usually located in contrib folder in the git-core package. If you're on Ubuntu like me, you can find it this way:

conf@laptop ~/php5.3 $ locate git-new
/usr/share/doc/git/contrib/workdir/git-new-workdir
conf@laptop ~/php5.3 $ 

This script creates several working copies sharing the same git repository, just as we need. I.e. if you make some commits in any working copy, they're available in all copies instantly. Read how it works here: http://nuclearsquid.com/writings/git-new-workdir/

Create working copies

Make working copies for 5.3 and 5.4 branch, assume that we use php-src for master:

conf@laptop ~ $ bash /usr/share/doc/git/contrib/workdir/git-new-workdir ./php-src ./php5.3 PHP-5.3
Already on 'PHP-5.3'
conf@laptop ~ $ bash /usr/share/doc/git/contrib/workdir/git-new-workdir ./php-src ./php5.4 PHP-5.4
Switched to branch 'PHP-5.4'
conf@laptop ~ $

Now you have your PHP5.3 branch checked out in ~/php5.3, PHP5.4 in ~/php5.4 and master in ~/php-src.

Make initial fix in 5.3 (better in separate branch):

cd ~/php-5.3
git checkout -b mybranch
[edit files]
git diff
git add <new files>
git commit -am 'Some really relevant commit message.'

Make sure that release branches are not stale.

cd ~/php-5.3
git fetch # download all remote changes but do not apply them
git checkout PHP-5.3 # make sure each working copy is on its release branch
git pull             # that's easier to write than git merge origin/PHP-5.3, although it calls remote repo one more time
cd ~/php-5.4
git checkout PHP-5.4
git pull
cd ~/php-src
git checkout master
git pull 

If there are any changes in PHP-5.3 branch, rebase our branch against them:

cd ~/php5.3
git checkout mybranch
git rebase PHP-5.3

Merge mybranch into PHP-5.3

cd ~/php5.3  # if you're not here yet
git checkout PHP-5.3
git merge --no-ff mybranch
git diff origin/PHP-5.3 # review changes

Merge upwards to 5.4 and 5.5:

cd ~/php-5.4
git checkout PHP-5.4
git merge --no-ff PHP-5.3
git diff origin/PHP-5.4 
cd ~/php-src
git checkout master
git merge --no-ff PHP-5.4
git diff origin/master

Push the changes

git push origin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment