GitHub: The unauthenticated git protocol on port 9418 is no longer supported

GitHub recently improved security, so you may get the error below like I did when I tried to install oh-my-zsh on a new Mac.


Anton.Perez@amp ~ % sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
Cloning Oh My Zsh...
fatal: remote error: 
  The unauthenticated git protocol on port 9418 is no longer supported.
Please see https://github.blog/2021-09-01-improving-git-protocol-security-github/ for more information.
/Users/Anton.Perez
Error: git clone of oh-my-zsh repo failed

You can test if it’s because you need to add an SSH key by running:


ssh -vvv git@github.com

You’ll get an error like so if so:


...
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
git@github.com: Permission denied (publickey).

If so, just generate a new key and add it to your GitHub account (see this. That’s it!

Git: Command to fix corrupted repository

I occasionally get fatal, such as:


error: cannot lock ref 'refs/remotes/origin/AB-123': is at dffbe642f088781a5e485227927e141ddb73443a but expected e377921a6d00f4d4c0463774990e03343683177e

Rebasing doesn’t work, but if you do the following it will resolve it:


git gc --prune=now

This guarantees to remove all git garbage.

NOTE: Make sure all your code has been committed before doing this.

Git: Syncing fork repo against upstream repo

In case you need to make sure your forked repo is up-to-date with the original repo (i.e. /git/original/HelloWorld vs /git/anton/HelloWorld), here’s what you need to do in your terminal:


$ git remote -v
$ git remote add upstream git@git.url.io:original/HelloWorld.git
$ git remote -v
$ git fetch upstream
$ git checkout master
$ git merge upstream/master
$ git merge upstream/master
Updating ad3aeb1c..3f5ef884
Fast-forward
pom.xml | 5 +-
26 files changed, 139 insertions(+), 578 deletions(-)

Ref: https://help.github.com/articles/syncing-a-fork/

How-to: Git Rebase

Adding here for my own purposes, but may be helpful to others. This rebases to master (or whatever branch) and then squashes all your commits into one commit! Sexy. 🙂


> git fetch --all
> git checkout [master]
> git pull
> git checkout [working branch name]
> git merge-base HEAD [master] 
> git reset --soft [hash] e.g.: 43e87200b8375fc5eba022ced353ab2917f2a746
> git status
> git commit -a -m "NOTES"
> git rebase [master]

Note: Only needed if conflicts between branch commit and master
> git add .
> git status
> git rebase --continue

> git diff origin/[working branch name]
> git push -f origin [working branch name]