Familiar with git, first time using perforce.
I am working on my own feature which I would not like to push to mainline remote repository.
I need something like git remote branches where:
I can commit my changes. Something like
git commit
I can push to remote private branch which does not merge. Something like
git push remote my-branch
Can merge changes from mainline into my branch. Somthing like
git merge master
.
I am trying to understand p4 branches, but the confused with the terminology a lot between p4 integrate
and p4 branch
. Moreover all the steps lead to p4 submit
which submits to the mainline instead of my branch.
Is there a way to submit to remote private branch?
I have tried the p4 branch steps here: https://www.perforce.com/perforce/doc.973/cmdguide/html/branchin.htm But it did not lead to submitting to private remote branch.
Perforce has a DVCS mode that's somewhat git-like, but unless there's a compelling reason not to (like limited connectivity or severe resource constraints on the server), the typical way of using Perforce is to do everything directly on the central server (the "remote repository").
p4 submit
in the typical model is essentiallygit commit
+git push
, because your "commit" goes directly to the remote server.So when you create a branch, you're doing that on the server as well. Branches in Perforce are simply folders that are copied from other folders (with lots of merge tracking semantics built on top of that simple copy operation), so to create your new feature branch from
//depot/main
you might run something like:This creates a new branch in the depot (as a folder called
features/road-rev
), and also syncs it to your workspace, so now all you need to do is:Changes you make in the
road-rev
branch are completely separate from themain
branch. To pull in newer changes frommain
you just repeat the sameinteg
command you used to create it, but add aresolve
to handle files that need merging:If you run the integrate command in the opposite direction (i.e. swap the order of the arguments), then changes get merged in the other direction. Once you grok the concept that you can use
integrate
to arbitrarily push changes from one set of files to another, branching is a very simple matter of defining different sets of files (usually as top-level folders) to represent different branched variants of code -- this is called "inter-file branching".If your admin has configured your depot to use streams the workflow is a little bit different (streams are "managed branches" that are meant to feel a little bit more like the git branches you're used to -- you can only have one stream in your workspace at a time, and you use the
switch
command to switch between them, rather than defining a client view that maps arbitrary branches/files to arbitrary parts of your workspace). You still have the same underlying representation of different branched variants being different folders in the depot, but there's a whole bunch of syntactic sugar on top that sort of hides that representation. To create a feature branch from a stream you'd do:which is similar to
git checkout -b road-rev
.