Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
git-offshoot

Description

Command git-offshoot allows the user to create a git branch, in a similar fashion to built-in git checkout -b.
It also creates an initial commit on that branch and stores the name of the "parent" branch in a file called PARENT.

Usage

git offshoot <branch-name>

Code

The code for this git command is as follows:

#!/bin/bash

CURRENT_BRANCH=`git rev-parse --abbrev-ref HEAD`
git checkout -b $1
echo $CURRENT_BRANCH > PARENT
git add PARENT
git commit PARENT -m "Initial commit on branch $1"

Install

To make the git command available, a git-offshot has to be created in your PATH and it should be executable.

Notes

  • No check on the presence of $1 in the shell script
  • Creates a PARENT file in the repo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.