Hi, I'm Anders

And I'm a Web Developer.

Learn more »

Howto use Git with Perforce

Written by | Date: | Tags:

Required Software:

  • Perforce
  • Python 2.7.x (in my case it was 2.7.6)
  • Git (in my case it was


If the software is not yet installed please install first.

Download the Git Perforce Bridge from here: https://github.com/git/git/blob/master/git-p4.py

Navigate to the directory where you installed Git and copy the downloaded file "git-p4.py" to the "bin" directory

Open up the Git Bash Console which was installed together with Git and verify that the
Git Perforce Bridge is enabled in your Git installation by typing

git p4.py

if you get the following, the bridge is correctly installed:

usage: C:\Program Files (x86)\Git\bin\git-p4.py <command> [options]

valid commands: clone, rollback, debug, commit, rebase, branches, sync, submit

Try C:\Program Files (x86)\Git\bin\git-p4.py <command> --help for command specific help.

Then we need to skip the Perforce Submit Edit dialog and instead let the Git commit message be used here.
We do that by typing the following in a Git Bash:   

git config git-p4.skipSubmitEdit true

To make this configuration permanent create a ".gitconfig" file in your home directory with the following content
    name = {FULLNAME}
    email = {EMAIL}

    skipsubmitedit = true

Create a P4 Settings file named .p4settings in c:\users\your_username and put the following in it

Open .bashrc in your home directory typocally in c:\users\your_username.
If the file does not exist create the it and put the following in it
export P4CONFIG=/c/users/your_username/.p4settings
Last but not least define your workspace mappings in Perforce by typing the following in Git Bash
p4 client

You can verify the settings by typing the following:

p4 info

General Usage:

1. Login with "p4 login" and clone a Perforce project:

git p4.py clone //depot/path/project

2. Make some changes to the project and commit locally to Git:

git add changed_file1
git add changed_file2
git commit -m "description of what was changed"
git commit -am "description of what was changed"

3. In the meantime somebody in the team submitted changes to the remote Perforce repository. Merge it to your local repository:

git p4.py rebase

4. Submit your local changes back to Perforce:
git p4.py submit


Q: I have made several commits to my local Git repository, will every commit in Perforce show up as a single commit just like in my local Git repository?
A: Yes

Q: What does "git p4.py rebase" do?
A: the Git Perfoce command "git p4.py rebase" is the equivalent to the git command "git pull"

Q: How can i see what is happening under the hood?
A: You can add the verbose parameter to every command to see what is going on under the hood. Example: git p4.py submit -v

Q: Where can i get more information?
A: Check out the git-p4 manual here: https://www.kernel.org/pub/software/scm/git/docs/git-p4.html


© Anders Godballe Hansen 2014