Git submodules

To add a submodule:

Add submodule (another repo):

$ git submodule add <path-to-repo>

Commit and push changes.

When cloning the parent project, only empty submodule folders get pulled. To actually pull the submodules you need to initialize and update the modules.

To install a submodule:

$ git submodule init

$ git submodule update

You can do this in one go by adding –recurse-submodules.

$ git clone –recurse-submodules <path-to-repo>

If you forgot the –recurse-submodules when cloning, you can combine the ‘init’ and ‘update’ command by running:

$ git submodules update –init

And the foolproof way:

$ git submodules update –init –recursive

Posted in Git

Change default branch from master to main

# Step 1 
# create main branch locally, taking the history from master
git branch -m master main

# Step 2 
# push the new local main branch to the remote repo (GitHub) 
git push -u origin main

# Step 3
# switch the current HEAD to the main branch
git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/main

# Step 4
# change the default branch on GitHub to main

# Step 5
# delete the master branch on the remote
git push origin --delete master
Posted in Git

Open Terminal shortcut

  1. Open and choose “Quick Action”.
  2. Set “Workflow receives current” to “no input” (last item in dropdown menu).
  3. Under Actions > Library > Utilities; drag “Run AppleScript” into the Workflow Builder area.
  4. Type in:
    on run {input, parameters}
    tell application "Terminal"
    end tell
    end run
  5. Save the file as something like: “Open Terminal”, and quit the
  6. In System Preferences > Keyboard > Keyboard Shortcuts > Services; select “General” and scroll to the end of the list; under General. Here you’ll should see “Open Terminal” (or whatever you called it when saving the Quick Action in …
  7. Click the “Add shortcut button” and type your preferred shortcut (Cmd + Alt + x).

AJAX in WordPress (the usual nightmare)

Add this to your ‘functions.php’ file:

wp_localize_script( 'portfolio-application', 'my_ajax_object', array(
// URL to wp-admin/admin-ajax.php to process the request
'ajaxurl' => admin_url( 'admin-ajax.php' ),

// generate a nonce with a unique ID "myajax-post-comment-nonce"
// so that you can check it later when an AJAX request is sent
// 'security' => wp_create_nonce( 'my-special-string' )

function get_data() {
$the_posttype = $_GET['posttype'];

$args = array(
'numberposts' => -1, // -1 is for all
'post_type' => $the_posttype, // or 'post', 'page'
'orderby' => 'title', // or 'date', 'rand'
'order' => 'ASC', // or 'DESC'
//'category' => $category_id,
//'exclude' => get_the_ID()
// ...

$cases = get_posts( $args );

header('Content-Type: application/json');

echo json_encode( $cases );

add_action('wp_ajax_get_cases', 'get_cases');
add_action('wp_ajax_nopriv_get_cases', 'get_cases');

Where ‘the-application’ is the enqueued script from where you make the $.ajax … or whatever call.

Add this to your javascript application (whatever file it may be ‘build’ into using a build process like gulp or what ever):

let config = {
action : 'get_data', // The metod in the function.php file to call
posttype : 'case' // Arbitrary data to pass to the call

url : my_ajax_object.ajaxurl,
type: 'GET',
data : {
'action' : config.action,
'posttype' : config.posttype
}).done(function ( response ) {
// Handle response
}).fail(function ( err ) {
// Handle error