Originally published on 2010-05-13; fully revised and updated.
This guide is for DevOps engineers and developers who use the p4 command-line client with Perforce. It turns the original quick command list into a structured reference you can use in day-to-day work: opening files, managing changelists, syncing revisions, integrating branches, and submitting safely.
Source article: Most User P4 Command Line – P4 Commands Reference.

How the p4 workflow fits together
Most teams follow a repeatable lifecycle: authenticate, sync, open files for add/edit/delete, review changelist content, resolve conflicts if needed, then submit.
flowchart TD
A[Check server and workspace] --> B[p4 login]
B --> C[p4 sync]
C --> D{Work needed}
D -- New file --> E[p4 add]
D -- Modify file --> F[p4 edit]
D -- Remove file --> G[p4 delete]
E --> H[p4 change review]
F --> H
G --> H
H --> I[p4 resolve when needed]
I --> J[p4 submit]
J --> K[p4 have or p4 sync verify]
Core p4 commands at a glance
| Command | Primary purpose | Example | Practical note |
|---|---|---|---|
| p4 add | Open new file(s) for addition | p4 add -t binary file.pdf | Can override typemap with -t. |
| p4 edit | Open existing file(s) for edit | p4 edit -t text+k doc/*.txt | File is checked out in workspace metadata. |
| p4 delete | Open file(s) for deletion | p4 delete //depot/README | Workspace file is removed immediately; depot changes on submit. |
| p4 revert | Discard pending file changes | p4 revert //depot/… | Returns open files to pre-opened state. |
| p4 change | Create or edit changelist spec | p4 change | Use numbered changelists for better control. |
| p4 changelists | List pending/submitted changelists | p4 changelists | Useful before submit or cleanup. |
| p4 submit | Send open file revisions to depot | p4 submit -c 41 | Final depot update happens here. |
| p4 sync | Copy depot files to workspace | p4 sync //depot/proj1/…@21 | Supports revision and changelist targets. |
| p4 have | Show synced revisions in workspace | p4 have | Helps verify client state. |
| p4 integrate (p4 integ) | Open files for branch/merge | p4 integ //depot/dev/… //depot/rel2/… | Creates targets if they do not exist. |
| p4 resolve | Resolve file conflicts | p4 resolve | Run after integrate/merge steps. |
| p4 login | Get authentication ticket | p4 login | Needed before protected operations. |
| p4 info | Display client/server connection details | p4 info | Good first diagnostic command. |
| p4 user | Create/edit/delete user specs | p4 user -d sammy | Deletion and edits may require elevated rights. |
| p4 admin | Administrative server operations | p4 admin stop | Restricted to admin/superuser roles. |
Command patterns you will use most
Add new files
Use p4 add to open files for addition. You can set file type, assign a changelist, or force-add a literal filename pattern.
p4 add -t binary file.pdf
p4 add -c 13 *
p4 add README ~/src/*.c
p4 add -f *.cCode language: JavaScript (javascript)
Edit, delete, and revert files
p4 edit -t text+k doc/*.txt
p4 delete //depot/README
p4 delete -c 40 file
p4 revert //depot/...
Manage changelists and submit
p4 change
p4 change -f 25
p4 changelists
p4 submit
p4 submit -c 41
Sync and inspect revision state
p4 sync
p4 sync file.c#4
p4 sync //depot/proj1/...@21
p4 haveCode language: PHP (php)
Integrate and resolve branch changes
p4 integ //depot/dev/... //depot/rel2/...
p4 resolve
p4 submitCode language: JavaScript (javascript)
Compare similar commands before you run them
| Command | When to use it | Immediate workspace effect | Depot effect |
|---|---|---|---|
| p4 add | New file should be versioned | File marked open for add | Created in depot on submit |
| p4 edit | Existing tracked file is being modified | File marked open for edit | New revision stored on submit |
| p4 delete | Tracked file should be removed | File removed from workspace and opened for delete | Deleted in depot history on submit |
| p4 revert | Discard pending local change | Open state removed; local edits discarded | No new depot revision |
| p4 submit | Finalize pending changelist | Pending open files are closed | Depot is updated with new revision metadata |
User, authentication, and administration commands
These commands are commonly used during setup, troubleshooting, or admin workflows. Run administrative operations carefully, especially in shared environments.
p4 info
p4 login
p4 passwd
p4 user
p4 user joe
p4 user -d sammy
p4 admin stop
P4CONFIG for repeatable local setup
The original post mentions P4CONFIG. In practice, teams often use it to keep consistent local client settings. Keep secrets out of shared files and follow your organization policies.
export P4CONFIG=.p4config
p4 infoCode language: JavaScript (javascript)
P4PORT=perforce.example.com:1666
P4USER=your-user
P4CLIENT=your-workspace
Common pitfalls and best practices
- Open files with
p4 add,p4 edit, orp4 deletebefore editing workflow-critical files. - Prefer numbered changelists for multi-file work; avoid large, mixed default changelists.
- Sync before integrate and before submit to reduce avoidable conflict resolution.
- Use
p4 haveandp4 changeliststo verify state before submit. - Be careful with wildcard patterns like
*.c; shell expansion behavior can differ by environment. - Treat
p4 admin stopas a controlled maintenance action, not a routine command.
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services — all in one place.
Explore Hospitals