Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clone branch with git-p4?

Tags:

git-p4

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.

like image 814
Noel Yap Avatar asked Mar 08 '13 23:03

Noel Yap


People also ask

How do I clone a branch in git?

You can clone a specific branch from a Git repository using the git clone –single-branch –branch command. This command retrieves all the files and metadata associated with one branch. To retrieve other branches, you'll need to fetch them later on.

What is clone in p4?

Clone is a combination of two operations, Init and Fetch . Clone fetches the files specified in a Remote Mapping and copies them to the new personal server. See Understanding remote mappings for more information on Remote Mappings.

What is p4 in git?

Often, the p4 repository is the ultimate location for all code, thus a rebase workflow makes sense. This command does git p4 sync followed by git rebase to move local commits on top of updated p4 changes.

How do I clone a specific branch in Terminal?

In order to clone a specific branch, you have to execute “git branch” with the “-b” and specify the branch you want to clone. $ git clone -b dev https://github.com/username/project.git Cloning into 'project'...


1 Answers

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
    
like image 97
cmcginty Avatar answered Oct 15 '22 09:10

cmcginty