How to clone branch with git-p4?

Noel Yap picture Noel Yap · Mar 9, 2013 · Viewed 9.5k times · Source

I did:

git p4 clone //depot/path/to/project/trunk/@all project

to create the master branch of project. Now I want to clone //depot/path/to/project/release to the release branch of project. How is that done?

UPDATE: Using --detect-branches doesn't work, either. It reports that it's updating two branches (when there are really three branches) but git branch reports only master exists.

Answer

cmcginty picture cmcginty · Mar 15, 2013

Here are my setup notes from when I was using git-p4. It might be helpful:

  • Download the p4 linux client. Store the file in ~/bin or /usr/local/bin and chmod +x

  • Setup git-p4 as root

    chmod 755 /usr/share/doc/git/contrib/fast-import/git-p4
    ln -s /usr/share/doc/git/contrib/fast-import/git-p4 /usr/local/bin
    
  • Define Git globals for git-p4

    git config --global alias.p4 '!git-p4'
    git config --global git-p4.detectRenames true
    git config --global git-p4.detectCopies true
    
  • Set defines for direct 'p4' usage

    export P4PORT=SERVER_NAME:PORT_NUMBER
    
  • Set login credentials

    export P4USER=USER_NAME
    export P4PASSWD=PASSWORD
    
  • Select Perforce branches using P4 'client'

    Run the 'p4 client' command, and add only the paths/branches you are interested in. If you want to name the client work space you can add an optional CLIENT_NAME argument to the end of the command. This will allow you to use different client definitions on the same machine.

    $ p4 client [CLIENT_NAME]
    
    View:
    //depot/main... //CLIENT_NAME/main...
    //depot/patch... //CLIENT_NAME/patch...
    //depot/dev... //CLIENT_NAME/dev...
    
  • Clone the repository

    • Simple import

      git p4 clone --use-client-spec --detect-branches //depot@all GIT_DIR
      
    • Advanced import

      git init PROJ; cd PROJ/
      git config git-p4.branchList main:patch
      git config --add git-p4.branchList main:dev
      git p4 clone --use-client-spec //depot@all .
      
  • Submit Changes Back to Perforce

    In order to submit changes to Perforce, it requires a client workspace, separate from the git working tree. It is recommend that the workspace is on the same file system your Perforce git working directory.

    Additionally, a reference to the workspace path is stored on the Perforce server, and will be used during the p4 submit command.

    The first step is to create the local client workspace. CLIENT_NAME is an optional argument. If you do not define it, p4 will use your host name.

    p4 client [CLIENT_NAME]
    

    You will be moved to a file editor before completing the p4 command. This lets you change any of the client settings before they are sent to the server. You must change the Root value to a new directory outside of your git tree (e.g. ../p4-working) Also, verify the Owner and Client values before exiting. These values are taking from your environment, and can not be changed in the editor.

    p4 clients | grep USERNAME
    

    If you did not use the default client name, it must be defined in your local git config:

    git config git-p4.client CLIENT_NAME
    

    When you are ready to push your code changes, use the commands:

    git p4 rebase
    git p4 submit
    

    You can remove clients from the sever when no longer in use:

    p4 client -d CLIENT_NAME