This is an old revision of the document!

Moving to Git FAQ

A good start is the ProGit book, which is available online.


The PHP git repositories are at There is a github mirror at

PEAR repositories are in This FAQ does not discuss PEAR.

Also see Git Workflow which discusses the workflow for PHP development.


The Git client is available in most major operating systems. If you don't already have a Git client, this list should be helpful:

  • Linux (apt-get)
sudo apt-get install git-core gitk
  • Linux (yum)
sudo yum install git gitk
  • Windows


  • Mac OS X

Git OS X Installer

Clone URL and Push URL

Read only urls are

Clone/Push URL (always requires password)


Hint: set the push URL (https or git@) with (see also, Quickstart below)

git remote set-url origin --push <URL>
$ git config --global "FIRSTNAME LASTNAME"
$ git config --global

$ git config merge.log true
adds a list of merged commits to the autogenerated commit message

$ git config checkout
alias for checkout. you can now use git co to checkout a branch

$ git config color.ui true
enable colored output for git commands

$ git config --add merge.ff false
Allows you to omit the "--no-ff" switch in merge.
Requires Git 1.7.6 or later.

Special cases:
$ git config core.filemode false
This is useful when you do not need to change files permissions in repository. 
If you need change file mode (+x for example) you must switch it option to true.

$ git config core.autocrlf input	 
This is usefull for web and doc projects. This setup should leave you with CRLF 
endings in Windows checkouts but LF endings on Mac and Linux systems and in the REPOSITORY. 
Do not use it if you need differents line endings in files! 


Consider setting up sensible .gitignore settings (see also

You can exclude filepatterns without touching the committed .gitignore: Set the config variable core.excludefile to a global exclude file or add the desired pattern to .git/info/exclude on a per-repo base.


$ git clone
$ cd php-src
// if you want to push throuh https
$ git config remote.origin.pushurl
// update repository
$ git pull --rebase
// will pull the new changes and apply your local changes on top of it.
// results in a linear history. make sure you understand what
// rebase does!

Committing and Merging

Always commit to the oldest branch. If your commit is good for PHP 5.3 and PHP 5.4, commit to PHP 5.3. Then merge your commit.

$ git clone
$ git branch --track 5.3 origin/PHP-5.3
$ git branch --track 5.4 origin/PHP-5.4
$ git branch --track master origin/master
$ git checkout 5.3
... edit Zend/zend.c ...
$ git commit Zend/zend.c
$ git checkout 5.4
$ git merge --log 5.3
$ git checkout master
$ git merge --log 5.4
$ git push

Multiple working copies workflow

This workflow allows you to keep checked-out branches in several folders. It removes the need to rebuild PHP every time you change branches.

Note: If you're not a core PHP developer, follow the steps in Workflow for external developers instead because the steps below require PHP source karma to push commits.

Clone repository

git clone

or if you're behind a firewall:

git clone
cd ~/php-src
git config remote.origin.pushurl

Find the git-new-workdir script

Find the git-new-workdir script, which is usually located in contrib folder in the git-core package:

conf@laptop ~ $ locate git-new-workdir

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:

Create working copies

Make working copies for PHP 5.3 and 5.4 branches, assuming that we use php-src for master:

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

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 a separate branch):

cd ~/php-5.3
git checkout -b <mybranch>
[edit files]
git diff
git add <new files>
git commit -a <changed files>

Use the New Commit Message Format for your 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             # this is easier to write than git merge origin/PHP-5.3, although it calls the 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 ~/php-5.3
git checkout <mybranch>
git rebase PHP-5.3

Merge mybranch into PHP-5.3

cd ~/php-5.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


To create a tag use the git tag command. Git distinguishes between lightweight and heavyweight tags. To create a heavyweight tag, you have to provide a tag message. Please always create heavyweight tags and use GPG keys to sign the tag.

  $ git tag -s PHP-5.3.9
  ... GPG passphrase ...
  ... edit tag message ..
  $ git push origin PHP-5.3.9

Using SSH

  • Add your SSH key to your profile on
    • you can set multiple keys in separate lines
    • if you get the “the ssh key doesn't seem to have the necessary format” error, check that your key has your email address at the end (it is mandatory currently to have an email address there)
  • Wait 10 minutes
  • Clone from or set new repository to

For web git repositories, don't forget the first slash or you'll get an error when commiting (“access denied”, or “there may be no repository at the given path”) :

git config remote.origin.pushurl 

Change Tracking

Github Pull Requests

There is a mailing list called All pull requests created for the user will go to this mailing list.

If you have commit rights to a mirrored PHP repository you can pull the requests and push it to the official repositories.

You cannot use the Merge button on GitHub for that. The PHP Organization on GitHub will not accept contributors. It's only for mirroring!

See the pull request related sections of the Git Workflow document for more information.

Commit Mails

Commit mails are send to the appropriate mailinglist (e.g. for commits to php-src). For every push a mail with an overview about the pushed changes will be mailed. Follow up mails for every commit will be send. They will include the patch, a list of changed paths and the commit message. The list of changed paths will also be the subject.


  1. Can I checkout a subdirectory only? Yes, but it's a rather new and experimental feature. See
  2. More questions? Just add them, I will try to answer them.
  3. What about commits that should not be merged upwards (say, only for 5.3)? Should you still merge them but make it so no changes actually take place? Otherwise, it will the next person merging that will have to deal with the conflict (or worse, the changes will be merged when they shouldn't have been)
vcs/gitfaq.1332881005.txt.gz · Last modified: 2017/09/22 13:28 (external edit)