How to create and use multiple P4 workspaces

It is sometimes useful to have more than one workspace in Perforce. I have found that this gives me more freedom to work on multiple bugs or features at the same time for the same branch.

  • To create a new workspace, we create a new P4 client. To do this, you need to provide a new client name:
$ p4 client my_client_2

This opens the configuration of a new client named my_client_2 in your favorite editor. Here you can provide the root directory for this client and mappings as your normally would. Save and exit the editor.

  • Create the root directory path you specified in the new client config:
$ mkdir -p /home/joe/p4_workspaces/my_workspace_2
  • You need to set this client name as the current client to inform P4 that its commands apply to this client. You do this by setting the P4CLIENT environment variable:
$ export P4CLIENT=my_client_2

Now you can run commands such as sync and they should work in this new workspace.

  • Switching between two or more P4 workspaces gets onerous if you need to set the above environment variable every time. One solution to overcome this is to create a P4 config file in the root directory of every workspace with the environment variables you want applied for that workspace.

Create a file named .p4config in the root directory of the new workspace, /home/joe/p4_workspaces/my_workspace_2 in this example, with the environment variables and their values you want to set:

P4CLIENT=my_client_2

Now when you are at any child directory of the new workspace, P4 will know that it has to use the above client config for its commands. You need to place such config files at the roots of all your workspaces to have a pleasant working experience when moving between workspaces.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.