Branches and merging
Work on new ideas without touching your main code, then bring them back in. Includes fixing merge conflicts, step by step.
Search for a command to run…
Work on new ideas without touching your main code, then bring them back in. Includes fixing merge conflicts, step by step.
A branch is a line of commits with a name. Every repository starts with one branch, main. When you make a new branch, it starts at the commit you're on, and from then on its commits are separate from main's.
That makes branches the safe way to try things:
mainmainmain: A ── B ── C \new-search: D ── EHere new-search started at C and has two commits of its own. main doesn't have D or E until you merge.
zev checkout -b new-searchThis makes the branch new-search at the current commit and switches to it. Any uncommitted changes come with you. Now commit as usual; the commits go on new-search:
zev add .zev commit -m "Search box, first version"See all branches; the one marked * is where you are:
zev branch main* new-searchzev checkout mainzev changes your files to match the branch: files that only exist on the other branch disappear, and come back when you switch back. Nothing is lost; it's all in the history.
If you have uncommitted changes that switching would overwrite, zev stops and tells you which file. You have three choices:
zev commit -m "Work in progress" # 1. commit them on this branchzev stash # 2. put them aside (zev stash pop later)zev checkout --force main # 3. throw them awayWhen the work on new-search is ready, go to main and merge:
zev checkout mainzev merge new-searchIf main hasn't changed since the branch started, zev simply moves main forward to include the branch's commits (a fast-forward). If both have new commits, zev combines them, file by file and line by line. When the two changed different lines, this just works.
On a team, the usual way is a pull request instead: push the branch and run zev pr, so others can review it first. See Collaboration from the terminal.
If main and your branch changed the same lines of a file, zev can't know which version you want. It stops before changing anything:
Can't bring 'new-search' in automatically: your commit "Tweak header" and 'new-search' changed the same lines of: index.htmlNothing was changed. To combine them by hand, run: zev merge new-search --resolveHere's how to combine them by hand. This is called resolving a conflict.
1. Start the resolve:
zev merge new-search --resolve2. Open each file it lists. zev marked the places where both changed:
<h1><<<<<<< mainWelcome to my site=======Welcome! Search below>>>>>>> new-search</h1>The part between <<<<<<< and ======= is one version, and the part between ======= and >>>>>>> is the other.
3. Edit it to what it should be. Keep one side, the other, or a mix, and delete the three marker lines:
<h1>Welcome! Search below</h1>4. Stage the files and finish:
zev add index.htmlzev merge --continueChanged your mind halfway? zev merge --abort puts everything back the way it was before step 1.
zev branch -d new-searchThis deletes only the name. Commits that were merged into another branch stay in its history.
Push a branch like any other:
zev push origin new-searchWhen you're on the branch, plain zev push does the same. Others get it with zev pull origin new-search, or by cloning with --branch new-search.