Strange GitHub Situation
Table of Contents
By default everything in my git workflow to uses ssh keys. It's always been easiest for me to configure my git interactions that way what with never having to worry about passwords. That said, this is the one time tonight I found a niche circumstance where the ssh key was inferior to https.
The Situation
I have a project that I contribute to daily and I use git as an extra form of redundancy not necessarily to track code changes. I don't particularly care about the edits, it's the "final product" (as final as an ongoing project can ever be) that I care about, so backing up to git is not always at the forefront of my mind when I contribute every day. Having not updated the repo in several weeks, I had amassed literally hundreds of files—many of them binaries so their file sizes were quite large. Tonight, since I had remembered, I decided it was as good a time as any to back up. Everything was fine when I staged and committed all the files, but when I went to push, I kept getting the following error:
send-pack: unexpected disconnect while reading sideband packet fatal: the remote end hung up unexpectedly
and…
client_loop: send disconnect: Broken pipe fatal: the remote end hung up unexpectedly
Needless to say, I was freaking out worried I wouldn't be able to back these changes up.
The Solution
Fortunately, I came across this stack overflow answer suggesting it was as simple as converting to the remote origin url to https.
git remote set-url https://github.com/<USERNAME>/<REPOSITORY>.git
Unfortunately, as the stack overflow pointed out, you will be prompted to authenticate using username and password going this route, a feature that was removed from GitHub on August 13th, 2021. Fortunately, they do have a blog post about it, which I didn't read instead opting for this stack overflow post giving the following answer in the comments:
git remote add origin https://<USERNAME>:<ACCESS-TOKEN>@github.com/<USERNAME>/<REPOSITORY>.git
However, since my origin was already added, that command failed, so I simply modified it to set the url instead like so:
git remote set-url origin https://<USERNAME>:<ACCESS-TOKEN>@github.com/<USERNAME>/<REPOSITORY>.git
With that answer in hand, I googled how to create an access token:
- In the upper-right corner of any page, click your profile photo, then click Settings.
- In the left sidebar, click Developer settings.
- In the left sidebar, click Personal access tokens.
- Click Generate new token.
- In the "Note" field, give your token a descriptive name.
And, following the instructions above, I was able to back up to GitHub.