Skip to content

Instantly share code, notes, and snippets.

Git Subtree Basics

If you hate git submodule, then you may want to give git subtree a try.

Background

When you want to use a subtree, you add the subtree to an existing repository where the subtree is a reference to another repository url and branch/tag. This add command adds all the code and files into the main repository locally; it's not just a reference to a remote repo.

When you stage and commit files for the main repo, it will add all of the remote files in the same operation. The subtree checkout will pull all the files in one pass, so there is no need to try and connect to another repo to get the portion of subtree files, because they were already included in the main repo.

Adding a subtree

Let's say you already have a git repository with at least one commit. You can add another repository into this respository like this:

#! /usr/bin/env bash
function zero_pad () {
n=$1
file=$2
padding=`seq 1 $n | sed 's/.*/0/' | tr -d '\n'`
zeroPadded="$padding$file"
if test -f "$zeroPadded"; then
echo "$zeroPadded exist"
else
@parallaxisjones
parallaxisjones / node.js PassThrough stream.md
Created January 25, 2019 17:57 — forked from bowin/node.js PassThrough stream.md
Node.js Stream PassThrough Usage
const {PassThrough} = require('stream')
const fs = require('fs')

const d = new PassThrough()  

fs.createReadStream('tt2.js').pipe(d)  // can be piped from reaable stream

d.pipe(process.stdout)                 // can pipe to writable stream 
d.on('data', console.log) // also like readable
@parallaxisjones
parallaxisjones / docready.js
Created August 30, 2018 15:38
Document REady
document.addEventListener("DOMContentLoaded", function(){
// Handler when the DOM is fully loaded
});
@parallaxisjones
parallaxisjones / script match
Created August 28, 2018 15:13 — forked from beck24/script match
preg_match_all <script></script> match
<?php
$html = <<<HTML
<html>
<head>
<script src="http://example.com"></script>
</head>
<body>
<div>
<script>
@parallaxisjones
parallaxisjones / customevent-polyfill.js
Created August 20, 2018 17:45 — forked from gt3/customevent-polyfill.js
custom event polyfill for IE 11 (>= 9 really)
// source: https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent
;(function() {
if (typeof window.CustomEvent === "function") return false
function CustomEvent(event, params) {
params = params || { bubbles: false, cancelable: false, detail: undefined }
var evt = document.createEvent("CustomEvent")
evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail)
return evt
}
@parallaxisjones
parallaxisjones / README.md
Created July 17, 2018 20:54 — forked from remarkablemark/README.md
Classes - ES5 vs ES6

JavaScript Classes - ES5 vs ES6

An example that shows the difference between creating a JavaScript class and subclass in ES5 and ES6.

Reference

Keybase proof

I hereby claim:

  • I am parallaxisjones on github.
  • I am parallaxisjones (https://keybase.io/parallaxisjones) on keybase.
  • I have a public key ASCuqWp2LShe3x9SUrSY-mO_BJ4mXHKUsTBdfD2eyLfYjAo

To claim this, I am signing this object:

@parallaxisjones
parallaxisjones / .eslintrc.js
Created June 26, 2018 18:29 — forked from nkbt/.eslintrc.js
Strict ESLint config for React, ES6 (based on Airbnb Code style)
{
"env": {
"browser": true,
"node": true,
"es6": true
},
"plugins": ["react"],
"ecmaFeatures": {
/*****************
* cellBlockA.js *
*****************
*
* Good morning, Dr. Eval.
*
* It wasn't easy, but I've managed to get your computer down
* to you. This system might be unfamiliar, but the underlying
* code is still JavaScript. Just like we predicted.
*