1077GitHub Desktop not pushing to server?

Increase the http.postBuffer:

git config http.postBuffer 524288000

1028Setting up GitHub Command-Line Access

This is a short, condensed instruction how to set-up command-line access to github.com. Written is response to onboard new FabAcademy students - and get them started with MkDocs.

This guides is for macOS 12 or higher. My Mac uses macOS Ventura 13.0.01.

Step 1: Creating a new SSH Key

Go to the .ssh directory.

$ cd ~/.ssh

Made new key:

$ ssh-keygen -t ed25519 -C "your_email@example.com"
  • Don't just copy, put in your email. I also added a password.
  • Also, don't copy the $, just the ssh-keygen -t ed25519 -C "your_email@example.com" part. But with your email.

You can name your key. For this example, we call it id_github_test.

Step 2: Adding SSH Key to ssh-agent.

$ eval "$(ssh-agent -s)"

Step 3: Adding Key Info to config

Open .ssh/config in your favourite text editor. If you want to stay at the command line, use nano.

Add the following:

Host *.github.com
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_github_test

Step 4: Adding the Key to ssh-agent

Adding private key to ssh-agent

$ ssh-add --apple-use-keychain ~/.ssh/id_github_test

This add the new key to the Apple Keychain.

If you used a passphrase when you created the key, you will be asked for it now.

Enter passphrase for /Users/georg/.ssh/id_github_test: 
Identity added: /Users/georg/.ssh/id_github_test (your_email@example.com)

Step 5: Adding Public Key to github.com

  • Log into Github
  • Profile > Settings > SSH and GPG Keys
  • Click 'New SSH Key'

Copy and paster your public key, in this example case, id_github_test.pub.

The tutorial on Github suggest to copy the public key using a command:

$ pbcopy < ~/.ssh/id_github_test.pub      

pbcopy - for paste board copy is the terminal interface to the macOS' Copy & Paste. pbcopy < read the content of a file into the copy memory. After running pbcopy you can press Command-V to paste the text.

  • Paste the copied SSH Public Key.

Step 5.1: Two-Factor Authentication at GitHub.com

I setup Two-Factor Authentication at GitHub.com, I had to confirm the addition of a new key via my mobile GitHub App. Your mileage might vary.

Step 6: Testing the connection

$ ssh -T git@github.com
Hi trembl! You've successfully authenticated, 
but GitHub does not provide shell access.

Ok, great! It worked!

Now you can clone, add, commit, push and pull!

Sources:

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

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-my-website.php

Webhook on GitHub for .htaccess protected directory:

https://username:passwd@www.trembl.org/update-my-website.php

Initialise

Go to your tmp directory, init the git repo and pull the repo

cd /my/local/tmp/directory/
git init        // initialize git
git reset --hard
git pull https://{$token}@github.com/{$repo}

Update

The update-my-website.php should look something like this:

<?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
exec('git reset --hard 2>&1') . ", ";

// get latest from github & store it in $msg
echo exec("git pull https://<span style="background:red">$token</span>@$repo 2>&1");
$msg = exec("git pull https://$token@$repo 2>&1");

if ($msg != "Already up to date.") {
  // Only copy if the git repo actually changed

  // 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

} else {
  echo($msg);
}

?>

Q & A

update-my-website.php protected by .htaccess?
860 Access a URL behind htaccess/htpasswd

Protect update.php ONLY with .htaccess?
940 Protecting a Single File with .htaccess

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

860Access a URL behind htaccess/htpasswd

Access a htaccess/htpasswd protected URL programmatically:

https://username:passwd@www.trembl.org/protected/area/

See also: Pulling a GitHub Repository with Tokens & Webhooks