Skip to content

Instantly share code, notes, and snippets.

@anabellaspinelli
Last active July 30, 2018 09:46
Show Gist options
  • Save anabellaspinelli/3e92eae63b41c2b0e56f619963e110d9 to your computer and use it in GitHub Desktop.
Save anabellaspinelli/3e92eae63b41c2b0e56f619963e110d9 to your computer and use it in GitHub Desktop.
Set up an https remote

Add an HTTPS remote for origin

Intro

If you're having the all time classic Broken pipe: the remote hung up unexpectedly error, a quick way to solve it is switching your computer to another wifi network (like the one your smartphone can provide).

But if this keeps happening it's a pain to have to do it constantly. So another solution can be to set up a new remote (the thing that knows where the GitHub repo is), but this time through https instead of ssh. This way, if you get the broken pipe, you can patch it up in a single command.

Steps

  1. Go to the repo in GitHub
  2. Select Clone or Download
  3. Select Use HTTPS Clone or download dialog
  4. Copy the link
  5. In you terminal window, navigate to the repo's directory
  6. Type git remote add origin-https {the address you copied from GitHub} and hit enter. This will try to add another remote, called origin-https which points to the repo in GitHub but through HTTPS instead of SSH.
  7. If you're be prompted for your GitHub username (not email!) and password and you have set up Multifactor Authentication in your account, your password won't work. You need to use a personal token, read for the steps to get it.

Set up a personal token

  1. Go back into GitHub > Settings > Developer Settings > Personal access tokens
  2. Generate a new token, give it Repo scopes only and copy it
  3. Retry the command at line 6 and when asked for your password, paste the personal token you just copied from GitHub.
  4. You're all set up.

How to use it

When you're happy with what you've done and trying to push things to GitHub, but GitHub's being rude and hanging up on you unexpectedly, just try this: git push origin-https {your-branch-name}

What this does is send your commits to the same GitHub repo, but through https, which won't hung up on you ever :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment