A Perforce branch is basically a new folder in your workspace, holding a copy of your project files. You usually use branches for the different project versions.
When you want to put work aside and share it with colleagues, you may use shelve
.
(image source: atlassian.com)
In Git, branches
are very different from Perforce branches, changelist or shelves. They are alternate change histories. We use Git branches as well for project versioning, to work on different features locally and even to share work in progress with colleagues. We'll learn more about that in the next courses. Basically, you create a new local branch with:
$ git checkout -b <new_branch>
# (equivalent to git branch < new_branch> + git checkout < new_branch>)
And you push your local branch to a remote repo:
$ git push <repository> <local_branch>:<new_remote_branch>
# (or simply git push <repository> new_branch to give to remote branch the same name as the local one)
You may need to put aside a work in progress and start working on something else. You can store a pending changelist without submitting it and discard shelved files:
$ p4 shelve -d
And go back to it:
$ p4 unshelve
In the next courses you'll learn different way to manage work in progress:
$ git stash # stashing your work
$ git push origin new_feature:new_feature # creating a remote feature branch
$ git checkout origin/master -t # moving from a branch to another
$ git commit -m "Fix in progress" # committing work in progress, to be edited later
$ git rebase -i origin/master # rebasing, editing and squashing commits at the end of the day
...
To integrate a bug fix from a Perforce branch to another, you usually use the merge-integrate process (integrate, merge or copy, then resolve, then submit).
With Git you have plenty of options. In the next courses you'll learn:
$ git cherry-pick <commit> # cherry-pick a commit from a branch
$ git rebase origin/master # rebase
$ git merge origin/master # or merge a branch to another
...
- perforce
branches
are not gitbranches
- perforce
shelves
vs gitstash
and featurebranches
- perforce
merge-integrate
vs gitmerge
andrebase