Imran's personal blog

September 14, 2013

Git for Perforce users

Filed under: Uncategorized — ipeerbhai @ 11:20 pm
Tags: , ,

Hello All,

I have been playing around with Git.  I’m a big fan of perforce.  After using GIT, I’m a bigger fan of perforce.

Git thinks differently — It assumes that all developers don’t trust each other, and only a “core few” really have rights to the source tree.  Each developer then works on their own dev branch.  Git also thinks of the changelist — you “add files” to a change.   Perforce thinks of the filesystem — You “add files” VIA the change.  The difference between “to the change” and “Via the change” is very different. Here’s a quick mapping of perforce commands to their GIT equal.

p4 add –> git add

p4 edit –> git add

p4 submit — > git commit, then git push, then pull ( pull request if you’re not trusted, push if you’re trusted. )

p4 opened –> git status

p4 info –> git remote -v


p4 branch X “//depot/foo/… //depot/bar/…”  –>  Different concept.  Perforce is using the branch as a map between one depot namespace and another.  Git uses the branch as a changelist tracker.  You can kind of map between them, but the differences can get you if you’re not careful.

  1. git checkout -b bar
  2. git push -u origin bar

p4 integrate //depot/foo/… //depot/bar/… –> many steps in git  Assuming branches foo/bar exist:

  1. git pull origin foo — this “syncs” the foo “namespace” ( origin tracker in git-speak ).
  2. git checkout bar — this switches to the bar “namespace”.
  3. git merge foo — the actually plays the diffs between the two spaces.
  4. git commit — you’ll need to resolve first, the commit the change locally.
  5. git push — same as p4 submit.
p4 branches –> git branch
Because GIT treats branches as trackers, to throw away a branch  and reset to the fork’s master tracker named “foo” in this example ( most people use either “master” or “develop”, but I chose foo because you can call this tracker anything you like ):
git reset –hard upstream/foo —
git push origin +foo
( the + means force the push )


In Git, common branch names are “master” and “develop”.  In perforce, there’s not really a concept of master, but rather, a depot namespace mapped to a client workspace.  Git doesn’t map — your clone matches the source tree of the branch you’re working on, always.  Again, I think perforce’s maps are better for developers, who often work on really small chunks of the tree, and don’t really need to clone an entire tree.



Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

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

You are commenting using your 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 )

Google+ photo

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

Connecting to %s

Create a free website or blog at

%d bloggers like this: