How many of you wanted to start using Git, but then learnt Perforce is much better for me 😉 specially for resolving conflicts! Did you know that you can use your favourite P4Merge tool with Git – and en-cash the power of Git with the comfort of using P4Merge tool for resolving conflicts! Isn’t that cool? I was totally new to git! I am sure many of us are, since we are used to our favourite P4V (Perforce Visual Client). But I keep hearing great things about Git.

So, one day I thought let me start using Git, started using it for some hobby projects. Installed Git for Desktop (visual client – by now u already know I am a big fan of Visual clients. I use command line too, but for simple tasks 😉 ). Initially everything was fine, and problem started only when 3 people started contributing (its good that 3 people started contributing) – because every time I wanted to commit my changes, I used to see conflicts and I had no clue how to resolve conflicts in Git. Bummer! I tried command line options, but it wasn’t a great option for me. You know me right. I also tried few other visual clients, but it was not even comparable to P4Merge tool provided by Perforce. May be I am used to it so much. Then, I said to myself – “Not now, may be someday I’ll start using Git. I am better of with Perforce for now.”, and I moved on. Until yesterday when our QE team started struggling about resolving conflicts in Git! Their story was no different than mine. They thought of creating “REST service automation test suite” in Git (it was a new module anyway). But within no time, they ended up in this mess of conflicts. The major problem is the default “Github client for desktop” doesn’t solve this problem well (doesn’t solve it at all). Time to think! I thought why can’t I use perforce merge with Git and googled it as if it was a new idea. Lol it was already there! I followed few simple instructions and in less 2-3 mins I was ready to go. Amazing! And the very next thing I wanted to do is to write this blog so that people like me – who love perforce but want to move to git – can get benefitted 🙂

Steps to integrate

Enough of talks, here are few simple steps (for Mac) of integrating P4Merge tool with git You can also visit https://gist.github.com/samsalisbury/5436108 (this is where I got these steps from)

  • Install P4Merge from Perforce official site for free (if you do not have it already)
  • Install Git (if you do not have it already)
  • vim ~/.gitconfig and add the following contents
[merge] 
keepBackup = false 
tool = p4merge 
[mergetool "p4merge"] 
cmd = /Applications/p4merge.app/Contents/Resources/launchp4merge "\"$PWD/$BASE\"" "\"$PWD/$REMOTE\"" "\"$PWD/$LOCAL\"" "\"$PWD/$MERGED\"" 
keepTemporaries = false 
trustExitCode = false 
keepBackup = false 
[diff] 
tool = p4merge 
[difftool "p4merge"] 
cmd = /Applications/p4merge.app/Contents/Resources/launchp4merge "\"$REMOTE\"" "\"$LOCAL\"" 
  •  Once the above configuration is done. you can do $ git mergetool to use p4merge

Keep sharing, Happy Coding 🙂

PS: For windows you can use the following commands

git config --global diff.tool p4merge

git config --global difftool.p4merge.cmd 'p4merge.exe $LOCAL $REMOTE'

git config --global difftool.prompt false


Leave a Reply

Your email address will not be published. Required fields are marked *