Search…
Branching

Branching

Branching and merging is probably one of Git's most powerful and commonly used feature.
A branch represents a separate line of development, created from a commit in another branch. It allows you to work on a parallel line of code, and later merge your changes back to the original branch. When you switch between branches you are performing a "checkout" of that branch. As such, your local development files will change accordingly.
More information about branch theory is given below, but let's get started on how you can use this powerful feature! A very common workflow for engineers starting on any new feature is to:
  1. 1.
    Create a new branch
  2. 2.
    Make changes on that branch
  3. 3.
    Merge the branch back into the main branch
The adage we gave in getting changes and making changes was to "pull before you push." However, all of this pushing and pulling gets annoying. Branching allows you to work in your own scratch area (a "branch") and then deal with merging only once when you've finished your changes.

Standard Workflow

While there is a lot of theory that goes into branching, the basic workflow in the Copia Desktop app is straightforward.
First, create a branch by clicking on the New Branch option.
Provide a name with relevant context, and select the Create Branch button.
Modify your code as you would normally. Commit your changes by clicking the Commit button. You'll notice that this now says "commit to add-a-rung," indicating you're no longer committing to the main branch.
You may see a number next to the Current Branch name in the desktop app. This indicates the Pull Request number. See the Code Review section for more information on this topic.
See merging for step-by-step instructions to complete the second half of this workflow.

Rename a Branch

When choosing to rename a branch, you must consider that in a distributed version control system, you have a local copy, there is a remote copy and there may be other local copies. You can change your local copy and the remote, but others will have to Pull the update and remove the old from their system individually.
In the Copia Desktop app, there is a rename option on the branch selector, but this only renames the local, and could cause confusion. Copia recommends following the process below.
To rename a branch, we will create a new branch from old, and delete the old. This can all be done from the Copia desktop app.
It is good practice to perform a Fetch prior to making any branch changes to make sure your local and remote are in sync.
In the Copia desktop app, switch to the branch you wish to rename. Then press the New branch button.
Enter a new name for the branch. Select the branch you would like to rename and then press the Create branch button.
Publish the new local branch to the Copia remote server by clicking the Publish branch option.
Right click on the old branch and delete it by clicking the Delete button.
Lastly, check the box to delete the branch on the remote, and press Delete.
At this point, you will want to alert anyone else using this branch so that they can update their local repository accordingly.

Branching in Theory

Following the above steps should be sufficient for anyone who wants to use a branching and merging workflow. However, it's useful to keep the mental model of branching in your head. The most common model looks like this.
You can think of each branch ("New Branch" / "New Feature Branch") as temporary deviations from the main branch at a particular point in time with the eventual goal of merging those features back into the main branch.
The goal of this documentation isn't to make you an expert on branching, just familiar with the common flows. There is plenty of material online about how branching works. We think much of this documentation is too complicated to be useful, and we hope the above is sufficient context to get you going.
If you do want to read more, we recommend Git's official documentation and also the Learning Git Branching Game
Last modified 1mo ago