Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Git / Bitbucket Feature Branches

Source: Confluence - Git / Bitbucket Feature Branches

Official Documentation

Required Reading:


Create a Feature Branch

Command-line Version

  1. Clone the main project:
cd ~/workspace
git clone git@bitbucket.org:path2response/co-op.git
cd co-op
  1. Create branch:
git branch <new-branch>
  1. Or create and checkout in one command:
git checkout -b <new-branch> <from-branch>

<from-branch> defaults to the branch you are currently on.

Using Bitbucket

  1. Go to the project in Bitbucket
  2. Click “Create Branch” button on the left
  3. Follow the instructions

Common Git Operations

Switch to a Branch

git checkout <branch-name>

<branch-name> can be main.

Sync Branch with Main

While on your branch (if local main is up to date):

git merge main

Merge Branch Back to Main

While on main:

git merge <branch-name>

Delete a Local Branch

git branch -d <branch-name>

Delete a Remote Branch

git push origin :<branch-name>

Full Graphical Comparison Between Branch and Main

Setup Your Git Difftool

In ~/.gitconfig:

[merge]
    tool = opendiff
[diff]
    tool = opendiff
  • Mac: opendiff (comes with XCode)
  • Linux: meld works well

Run Comparison Script

#!/bin/bash

# TODO Parameterize
branchname=PATH-1529

rm -rf ~/temp/diffs/$branchname
mkdir -p ~/temp/diffs/$branchname
cd ~/temp/diffs/$branchname

git clone git@bitbucket.org:path2response/co-op.git
cd co-op
git fetch

git checkout $branchname

git difftool main..$branchname

Quick Reference

ActionCommand
Clone repositorygit clone git@bitbucket.org:path2response/<repo>.git
Create branchgit branch <branch-name>
Create and checkoutgit checkout -b <branch-name>
Switch branchesgit checkout <branch-name>
Sync with maingit merge main (while on feature branch)
Merge to maingit merge <branch-name> (while on main)
Delete local branchgit branch -d <branch-name>
Delete remote branchgit push origin :<branch-name>
Push branch to origingit push -u origin <branch-name>
Pull latestgit pull
Fetch and prunegit fetch -p