`git blast`

If you use my git dev, you may also find git blast useful.

It deletes both local and remote branch of the same name.

The code below is probably old and buggy so best grab the latest from my publicly accessible dotfiles and paste the git dev block into the [alias] section of your ~/.gitconfig file.

Probably buggy WIP code:


    ; `git blast `
    ;   Delete branch both local and at origin.
    blast = "!blast() {\
        Y=\"\\033[1;33m\";\
        B=\"\\033[1;34m\";\
        N=\"\\033[0m\";\
        G=\"\\033[1;32m\";\
        R=\"\\033[1;31m\";\
        \
        branch=$1;\
        \
        [ \"$branch\" = \"master\" ]\
            && printf \"\\n\\t${R}NOPE!\\n\\tNot deleting your master branch!\\n\\tARE YOU MAD?!${N}\\n\\n\"\
            && exit 1;\
        \
        printf \"\\n${Y}Switching to master${N}\\n\";\
        printf \"${B}git checkout master ...${N}\\n\";\
        git checkout master;\
        \
        printf \"\\n${Y}Fetching refs${N}\\n\";\
        printf \"${B}git fetch ...${N}\\n\";\
        git fetch;\
        \
        printf \"\\n${Y}Deleting remote branch 'origin/${branch}'${N}\\n\";\
        printf \"\\n\\t${G}PEW! PEW!${N}\\n\";\
        printf \"\\n${B}git push --delete origin '${branch}' ...${N}\\n\";\
        git push --delete origin \"${branch}\";\
        \
        printf \"\\n${Y}Deleting local branch '${branch}'${N}\\n\";\
        printf \"\\n\\t${G}PEW! PEW!${N}\\n\";\
        printf \"\\n${B}git branch -D '${branch}' ...${N}\\n\";\
        git branch -D \"${branch}\";\
        \
        printf \"\\n\\t${G}  POOF!${N}\\n\\n\";\
    };\
    blast"


`git dev` – git out of the way and start coding

95% of the time I get started developing by doing one of three things:

  1. I need to switch to an existing local branch
  2. I need to make a new local branch that tracks an existing branch
  3. I need to make a new remote branch and a local one that tracks it

With just a little bit of `.gitconfig` shenanigans, it can be done with a single command that makes the right decisions most most of the time.

`git dev newbranch [frombranch]` will:

  1. switch to the local `newbranch` if it exists
  2. create local `newbranch` and track `origin/newbranch` if the latter exists on remote
  3. create `origin/newbranch` (from `master` or `frombranch` when specified) and local `newbranch` tracking the `origin/newbranch` it.

The code below is probably old and buggy so best grab the latest from my publicly accessible dotfiles and paste the git dev block into the [alias] section of your ~/.gitconfig file.

Most likely out of date snip:

    ; `git dev` - a shortcut to your dev branch.
    ;
    ; USAGE:
    ; git dev  [branch_from | default:master]
    ;
    ; FUNCTION:
    ; if  already exists locally:
    ;   switch to the local branch.
    ; if  already exists at origin:
    ;   create a local branch tracking the remote one.
    ; if it does not:
    ;   create  at origin
    ;   and a local one tracking the remote one.
    ; start dev-ing
    dev = "!dev() {\
        R=\"\\033[1;31m\";\
        G=\"\\033[1;32m\";\
        Y=\"\\033[1;33m\";\
        B=\"\\033[1;34m\";\
        W=\"\\033[1;37m\";\
        N=\"\\033[0m\";\
        \
        newbranch=$1;\
        frombranch=$2;\
        \
        [ \"$newbranch\" = \"master\" ]\
            && printf \"\\n\\t${R}NOPE!\\n\\tNot messing with master branch!\\n\\tARE YOU MAD?!${N}\\n\\n\"\
            && exit 1;\
        \
        [ -z $frombranch ] && frombranch='master';\
        \
        [ -z $newbranch ]\
            && printf \"\\n${R}Specify branch name!${N}\\n\"\
            && printf \"\\n${Y}USAGE: git dev '' [branch_from | default:master]${N}\\n\"\
            && printf \"\\n\" && exit 1;\
        \
        printf \"\\n${Y}Checking if branch '${newbranch}' already exists locally${N}\\n\";\
        printf \"${B}git rev-parse --verify '${newbranch}' ...${N}\\n\";\
        git rev-parse --verify \"${newbranch}\";\
        [ \"$?\" == \"0\" ]\
            && printf \"${R}Found local branch '${newbranch}'${N}\\n\"\
            && printf \"\\n${Y}Switching to local branch '${newbranch}'${N}\\n\"\
            && printf \"${B}git checkout '${newbranch}' ...${N}\\n\"\
            && git checkout \"${newbranch}\"\
            && printf \"\\n${G}You are now on your ${W}ALREADY EXISTING${G} local branch '${newbranch}'\\n\"\
            && printf \"\\nDo your DEVest!${N}\\n\\n\"\
            && exit 0;\
        \
        printf \"${R}No local branch '${newbranch}' found.${N}\\n\";\
        printf \"\\n${Y}Checking if branch '${newbranch}' exists at origin${N}\\n\";\
        printf \"${B}git fetch ...${N}\\n\" && git fetch;\
        printf \"\\n${B}git ls-remote --heads origin '${newbranch}' ...${N}\\n\";\
        alreadythere=$(git ls-remote --heads origin ${newbranch});\
        \
        [ -z \"$alreadythere\" ]\
            && printf \"${R}No remote branch '${newbranch}' found at origin${N}\\n\"\
            && printf \"\\n${Y}Creating '${newbranch}' locally and at origin by branching from '${frombranch}'${N}\\n\"\
            && printf \"${B}git checkout '${frombranch}' ...${N}\\n\"\
            && git checkout \"${frombranch}\"\
            \
            && printf \"\\n${Y}Updating '${frombranch}'\\n\"\
            && printf \"${B}git pull --rebase ...${N}\\n\"\
            && git pull --rebase\
            \
            && printf \"\\n${Y}Branching into '${newbranch}' from '${frombranch}'\\n\"\
            && printf \"${B}git checkout -b '${newbranch}' ...${N}\\n\"\
            && git checkout -b \"${newbranch}\"\
            \
            && printf \"\\n${Y}Creating '${newbranch}' on remote\\n\"\
            && printf \"${B}git push origin '${newbranch}' ...${N}\\n\"\
            && git push origin \"${newbranch}\"\
            \
            && printf \"\\n${Y}Setting '${newbranch}' to track remote\\n\"\
            && printf \"${B}git branch -u 'origin/${newbranch}' ...${N}\\n\"\
            && git branch -u \"origin/${newbranch}\"\
            && printf \"\\n${G}You are now on your ${W}BRAND NEW LOCAL BRANCH${G} '${newbranch}'\\n\"\
            && printf \"\\twhich is tracking a ${W}BRAND NEW${G} 'origin/${newbranch}'\\n\"\
            && printf \"\\t\\twhich was ${W}BRANCHED FROM${G} 'origin/${frombranch}'\\n\"\
            && printf \"\\nDo your DEVest!${N}\\n\\n\"\
            && exit 0;\
        \
        [ -n \"$alreadythere\" ]\
            && printf \"\\n${Y}Branch '${newbranch}' already exists at origin.\\n\"\
            && printf \"\\nBranching and tracking from 'origin/${newbranch}'\\n\"\
            && printf \"${B}git branch '${newbranch}' --track 'origin/${newbranch}' ...${N}\\n\"\
            && git branch $newbranch --track \"origin/${newbranch}\"\
            && printf \"\\n${Y}Checking out '${newbranch}'${N}\\n\"\
            && printf \"\\n${B}git checkout '${newbranch}' ...${N}\\n\"\
            && git checkout \"${newbranch}\"\
            && printf \"\\n${G}You are now on your ${W}BRAND NEW LOCAL BRANCH${G} '${newbranch}'\\n\"\
            && printf \"\\twhich is tracking an ${W}ALREADY EXISTING${G} 'origin/${newbranch}'\\n\"\
            && printf \"\\nDo your DEVest!${N}\\n\\n\"\
            && exit 0;\
        \
    };\
    dev"



Hope you find it as handy as I have.
Happy DEVing!

Assembly

A non-technical coworker asked me what is “assembly language.”

Analogy to the rescue. My reply:

Assembly Language is a very low level programming language that directly instructs the computer’s processing chip, memory an registers what to do. It’s the closest to hardware programmers ever get.
I’d be surprised if they still teach it in undergrad programs. Most languages used for most purposes today are high level, meaning each instruction translates to a whole lot of more specific assembly instructions.
As an analogy, if you were programming a human to walk, in a higher level language your first instruction might be “right_leg:step_forward,” in assembly you’d start with “motor_cortex:send_electric_charge_down_the_right_sciatic_nerve…”
It’s a whole other level of instruction granularity.

Seemed to make sense to her, so perhaps worth sharing?