Skip to content

Instantly share code, notes, and snippets.

@Veejay
Last active June 29, 2016 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Veejay/79907a484d2b12d150d6f82ef36e66de to your computer and use it in GitHub Desktop.
Save Veejay/79907a484d2b12d150d6f82ef36e66de to your computer and use it in GitHub Desktop.
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