I wanted to publish this post couple of months earlier, but forgot about it 🙂 I hope that informations below are not very outdated and you can use it for something.
When I started using git, I was just unable to use other source version control system, because of their lack of functionality or performance (comparing to other I used to work with during my professional career: svn, cvs, cmvc, perforce). At one of my previous companies I used to work for, they have all projects configured under perforce system. I just had to find the way to use git as my local repository. After reading couple of blog posts and searching through forums I found really simple method to do this.
First of all, you have to install p4 command line tools (I assume, you already have p4 gui client installed). You can find them here: http://www.perforce.com/downloads/complete_list
For Mac OSX, you can also use MacPort or Homebrew.
Next step is to configure environment variables (I assume again, that you already have access to p4 server and you have configured your workspace). Place following variables (with values matching your settings) within your ~/.bashrc file, or similar if you are using shell different than bash:
export P4CLIENT=my.cool.workspace #workspace name export P4PORT=10.0.0.5:1666 #p4 server ip and port export P4USER=user.name #p4 user name #export P4PASSWD= #your p4 password export P4EDITOR=vim #command line text editor you like
It’s better not to place password here. Without P4PASSWD variable, from time to time you have to use “p4 login” command to authenticate to p4 server. It’s more secure.
to verify if the workspace mapping is correct. For other settings verification use this command:
You have p4 command line client configured, now it’s time to install p4-git. It’s located in git repository on github, so clone latest git repository to your favourite location with command:
git clone https://github.com/git/git.git
One more step. create symbolic link to the git-p4.py script:
sudo ln -s <cloned_git_repository_location>/git-p4.py /use/bin/git-p4
Now it’s time to get p4 repo and start using it! To clone p4 repository, use command:
git p4 clone //path/to/project/at/p4
of course using your path to project. Adding “@all” at the end of the path will get all the project’s history into your local git repository:
git p4 clone //path/to/project/at/p4@all
That’s it! You have full featured local git repository and you can do all that nice rebase, stash, merge, branch things.
To download latest changes from the p4 server (like git pull), you have to run command:
git p4 rebase
Pushing your commits (like git push) to p4 server its done with:
git p4 submit
Have a nice giting! 🙂