1002Rename Branches on GitHub

Renaming a branch on Github is straight-forward:

The "Lean More" link has some instructions how to update the local environments:

Your members will have to manually update their local environments. We'll let them know when they visit the repository, or you can share the following commands.

git branch -m oldbranchname newbranchname
git fetch origin

Username for 'https://github.com': trembl
Password for 'https://trembl@github.com': 

I tried automatically to log-in with my GitHub Password.

remote: Support for password authentication was removed on 
August 13, 2021. Please use a personal access token instead.
remote: Please see https://github.blog/2020-12-15-token-
authentication-requirements-for-git-operations/ for more information.

https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/

Get a Personal Access Token

Ok, we need a Personal Access Token instead of the password!

Go to github.com > Settings > Developer Settings > Personal access tokens, and generate a new token with full repo access.

Once we use the token instead of the password, it works.

git branch -u origin/main main
# Branch 'main' set up to track remote branch 'main' from 'origin'.
git remote set-head origin -a
# origin/HEAD set to main

988Reset Local Git Repo

git reset --hard origin/main

main is the name your main branch.

976Git, Mac, SSH Keys and the OSX Keychain

When using git with a key that has a passphrase, you are asked the passphrase every time you pull/push. To make this a bit more convenient, add the key to the OSX Keychain.

Store key in OSX Keychain:

ssh-add -K ~/.ssh/my_key

Open .ssh/config

Host *
  UseKeychain yes
  AddKeysToAgent yes
  IdentityFile ~/.ssh/my_key

946Pulling a GitLab Repository with Tokens & Webhooks

Update from 864 Pulling a GitHub Repository with Tokens & Webhooks

GitLab requries a gitlab-ci-token: prefix:

$token = 'gitlab-ci-token:abcdefghijklmopq'

944Overwrite changes with git pull

git pull does not overwrite any changed files by default. If you want to overwrite - and loose - any changes, use git reset --hard origin/master.

864Pulling a GitHub Repository with Tokens & Webhooks

Here is how to sync a WordPress Theme from Github to your own server:

Create a Personal Access Token on GitHub


Webhook on GitHub:
https://www.trembl.org/update.php
Webhook on GitHub for .htaccess protected directory:
https://username:passwd@www.trembl.org/update.php
initialise:
cd $temp_dir git init // initialize git git pull https://{$token}@github.com/{$repo}
update.php:
<?php // path to local tmp directory $temp_dir = '/my/local/tmp/directory/'; // path to local theme directory $theme_dir = "/my/local/theme/directory/"; // access token from GitHub $token = 'abcdefghijk'; // Repo $repo = 'github.com/trembl/SuperNiceRepo.git'; // - - - - - // change to local git directory chdir($temp_dir); // resets local git echo exec('git reset --hard 2>&1') . ", "; // get latest from github echo exec("git pull https://$token@$repo 2>&1"); // delete theme dir echo "\n\nDeleting Theme Directory.\n"; echo exec("rm -rf $theme_dir*"); // * deletes all files within the directory // Copying Theme from $temp_dir to $theme_dir echo "\n\nCopying Theme from tmp folder to wp-content.\n"; echo exec("cp -a $temp_dir/* $theme_dir"); // cp -a $temp_dir/* copies everything _except_ invisible files, like .git ?> update.php protected by .htaccess? 860 Access a URL behind htaccess/htpasswd
Protect update.php ONLY with .htaccess? 940 Protecting a Single File with .htaccess


Q & A

I get the following error message: Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set). That means git is not initalized. Run git init