facebook / sapling

A Scalable, User-Friendly Source Control System.
https://sapling-scm.com
GNU General Public License v2.0
6k stars 271 forks source link

CREATE NEW BRANCH #917

Closed 0x451 closed 1 month ago

0x451 commented 1 month ago

I want to create a new branch, what should I do? I looked through the docs and saw instructions for creating bookmarks, but I want to create a new branch to work on.

MKHokinson commented 1 month ago

Apologies if I get some terminology wrong WRT git vs. sapling workflows, but it sounds like you want to store a commit somewhere other than the trunk base (i.e. dev or main).

On git, pushing a new feature set might look like this:

On sapling, this is going to be pretty similar. Every diff (commit) is contained on its own branch, and these diffs are stacked on one another. Under the hood this would look like dev <- diff1 <- diff2 <- ... <- diffN. At a high level, you can generally get by by treating one branch the same as one commit, which is referred to as a diff.

To do this on sapling, there is a whole set of docs on the CLI tools/commands, but I'll stick to the Interactive Smartlog. Everything you do on the Interactive Smartlog will also display the commands being run, which is a good way to learn as well. You'll start be checking out (sl goto) the base branch (sometimes referred to as trunk) and make your first set of changes. Then you can open the smartlog where you'll see the staged changes. You can then provide a name for the diff, and hit Commit. This is what creates the new diff outside of the trunk. You can continue to make changes, and either put these changes on a new diff (which is useful when they are dependent but not necessarily related), or you can amend the previous diff. You can think of amend to serve a similar purpose to adding a new commit on a single branch.

There are some other issues here and the sapling docs which explain the different push/review/land strategies, as sapling gives you a couple of options.

I know this is hand wavy, and might be technically wrong, but this is how I learned to understand everything a few years ago when getting started with sapling.